Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Ficheiro lufactsp.m
[L,U]=lufactsp(A) Calcula a decomposiao LU de Crout de A sem escolha
de pivot.
ou [L,U,x]=lufactsp(A,b,kt).
L e a matriz triangular inferior, U e a matriz triangular
superior tal que L*U=A e
x e a soluao que so e calculada se existir 3 parametros de saida.
Se nao existir x so e necessario fornecer como parametro de entrada A.
Conhecido L e U, para resolver Ay=c basta fazer aux=L\c e y=U\aux.
O vector b deve ser coluna mas a funao aceita tambem que seja linha.
Se kt existir e for igual a 1 e, se existir o 3 parametro x, aparece no ecran
a matriz L e a soluao L-1*b e a matriz U e a soluao final U-1*(L-1*b).
EXEMPLO
[L,U,x]=lufactsp([1 1 1 1;2 3 1 5;-1 1 -5 3;3 1 7 -2],[10 31 -2 18]',1)
Ficheiro lucroutcp.m
[L,U]=lucroutcp(A) Calcula a decomposiao LU de Crout de A com
escolha parcial
escalonada. .
ou [L,U,d,x]=lucroutcp(A,b,kt).
L e uma permutaao da matriz triangular inferior, U e a matriz
triangular
superior tal que L*U=A, d o vector com a ordem de pivotagem das
linhas
(L(d,:) e uma matriz triangular inferior) e
x e a soluao que so e calculada se existir 4 parametros de saida.
Se nao existir x so e necessario fornecer como parametro de entrada A.
Conhecido L e U, para resolver Ay=c basta fazer aux=L\c e y=U\aux.
O vector b deve ser coluna mas a funao aceita tambem que seja linha.
Se kt existir e for igual a 1 e, se existir o 4 parametro x, aparece no ecran
o vector escala, d, a matriz L e a soluao y=L-1*b
e a matriz U e a soluao final U-1*y.
EXEMPLO
[L,U,d,x]=lucroutcp([1 1 1 1;2 3 1 5;-1 1 -5 3;3 1 7 -2],[10 31 -2 18]',1)
Remarks
Most of the algorithms for computing LU factorization are variants of
Gaussian elimination. The factorization is a key step in obtaining the inverse
with inv and the determinant with det. It is also the basis for the linear
equation solution or matrix division obtained with \ and /.
Arguments
X
Square matrix to be factored
thresh Pivot threshold for sparse matrices. Valid values are in [0,1]. The default is 1.
L
U
P
Examples
Start with
A=
1 2 3
4 5 6
7 8 0
To see the LU factorization, call lu with two output arguments:
[L,U] = lu(A)
L=
0.1429 1.0000
0
0.5714 0.5000 1.0000
1.0000
0
0
U=
7.0000 8.0000 0.0000
0 0.8571 3.0000
0
0 4.5000
Notice that L is a permutation of a lower triangular matrix that has 1's on the permuted
diagonal, and that U is upper triangular. To check that the factorization does its job,
compute the product: L*U which returns the original A. Using three arguments on the
left-hand side to get the permutation matrix as well
[L,U,P] = lu(A)
returns the same value of U, but L is reordered:
L=
1.0000
0
0
0.1429 1.0000
0
0.5714 0.5000 1.0000
U=
7.0000 8.0000
0
0 0.8571 3.0000
0
0 4.5000
P=
0 0 1
1 0 0
0 1 0
To verify that L*U is a permuted version of A, compute L*U and subtract it from P*A:
P*A - L*U
.
.
.
Ficheiro iter.m
[x,k]=iter(C,d,x0,tol,itmax) resolve o sistema x=Cx+d usando o metodo
iterativo
ou
[x,k,rerr,Y]=iter(C,d,x0,tol,itmax,kt)
Os dados sao a matriz C n*n e o vector d n*1, o ponto inicial x0 (vector
n*1)
- a tolerancia tol (do criterio de paragem rerr=||xi-x(i-1)||/(||xi||+eps)<tol)
a norma usada e a norma infinito)
e o numero maximo de iteraoes itmax.
- Se existir kt e kt=1 e fornecida uma tabela com as iteraoes.
Fornece a soluao x, obtida em k iteraoes, o rerr e a
tabela Y com todas as iteraoes (coluna 1 = vector x0)
assim como ||xi-x(i-1)|| correspondente, na ultima linha
EXEMPLO
[x,k]=iter([0 2/7 -1/7 0;1/9 0 3/9 -1/9;-0.2 0 0 -0.1;-1/6 1/6 -1/6 0],[17/7;13/9;1.5;10/6],[0;0;0;0],1.e-3,30,1)