Sei sulla pagina 1di 7

Anlise Numrica LEC - Help

Resoluo de Sistemas lineares


Mtodos directos
Ficheiro gaussepp.m
gaussepp Metodo de eliminaao de Gauss com escolha parcial escalonada
[x,d]=gaussepp(A,b)
ou [x,d]=gaussepp(A,b,kt)
Resolve o sistema Ax=b
x e a soluao e d o vector com a ordem de pivotagem das linhas.
Se kt existir e for igual a 1 aparece escrita a matriz aumentada, o vector
escala, o vector d e a matriz transformada aumentada.
EXEMPLO
x=gaussepp([0.0002 1.471;0.2346 -1.317],[1.473; 1.029],1)

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)

Anlise Numrica LEC - Help

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)

Anlise Numrica LEC - Help

Ficheiro lu.m ( funo Matlab)


lu LU matrix factorization ( de doolitle)
Syntax
[L,U] = lu(X)
[L,U,P] = lu(X)
lu(X)
lu(X, thresh)
Description
The lu function expresses a matrix X as the product of two essentially
triangular matrices, one of them a permutation of a lower triangular matrix
and the other an upper triangular matrix. The factorization is often called the
LU, or sometimes the LR, factorization.
[L,U] = lu(X) returns an upper triangular matrix in U and a psychologically
lower triangular matrix (i.e., a product of lower triangular and permutation
matrices) in L, so that X = L*U.
[L,U,P] = lu(X) returns an upper triangular matrix in U, a lower triangular
matrix in L, and a permutation matrix in P, so that L*U = P*X.
lu(X) returns the output from the LAPACK routine DGETRF or ZGETRF.
lu(X,thresh) controls pivoting for sparse matrices, where thresh is a pivot threshold in
[0,1]. Pivoting occurs when the diagonal entry in a column has magnitude less than thresh
times the magnitude of any sub-diagonal entry in that column. thresh = 0 forces diagonal
pivoting. thresh = 1 is the default.

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

A factor of X. Depending on the form of the function, L is either


lower triangular, or else the product of a lower triangular matrix with
a permutation matrix P.
An upper triangular matrix that is a factor of X.
The permutation matrix satisfying the equation L*U = P*X.

Anlise Numrica LEC - Help

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
.
.
.

Anlise Numrica LEC - Help

Ficheiro chol.m (funo Matlab)


chol
Cholesky factorization
Syntax
R = chol(X)
[R,p] = chol(X)
Description
The chol function uses only the diagonal and upper triangle of X. The lower triangular is
assumed to be the (complex conjugate) transpose of the upper. That is, X is Hermitian.
R = chol(X), where X is positive definite produces an upper triangular R so that R'*R =
X. If X is not positive definite, an error message is printed.
[R,p] = chol(X), with two output arguments, never produces an error message. If X is
positive definite, then p is 0 and R is the same as above. If X is not positive definite, then
p is a positive integer and R is an upper triangular matrix of order q = p-1 so that R'*R =
X(1:q,1:q).
Examples
The binomial coefficients arranged in a symmetric array create an interesting positive
definite matrix.
n = 5;
X = pascal(n)
X=
1 1 1 1 1
1 2 3 4 5
1 3 6 10 15
1 4 10 20 35
1 5 15 35 70
It is interesting because its Cholesky factor consists of the same coefficients, arranged in
an upper triangular matrix.
R = chol(X)
R=
1 1 1 1 1
0 1 2 3 4
0 0 1 3 6
0 0 0 1 4
0 0 0 0 1
Destroy the positive definiteness (and actually make the matrix singular) by subtracting 1
from the last element.
X(n,n) = X(n,n)-1
X=
1 1 1 1 1
1 2 3 4 5
1 3 6 10 15
1 4 10 20 35
1 5 15 35 69
Now an attempt to find the Cholesky factorization fails.

Anlise Numrica LEC - Help

Resoluo de Sistemas lineares


Mtodos Iterativos
Ficheiro jacobi.m ( Kharab modificado )
[x,k]=jacobi(A,b,x0,tol,itmax) Solve the system Ax=b using Jacobi
iteration method.
ou
[x,k,rerr,Y]=jacobi(A,b,x0,tol,itmax,kt)
Os dados sao a matriz n*n e o vector b 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 infinita)
e o numero maximo de iteraoes itmax.
- Se existir kt e kt=1 e fornecida uma tabela com as iteraoes.
Esta versao foi modificada do original (Kharab) vectorizando-a e para
aceitar
parametros de saida.
Fornece a soluao x, obtida em k iteraoes, o rerr e a
tabela Y com todas as iteraoes (coluna 1 = vector x0)e na ultima
linha ||xi-x(i-1)||
EXEMPLO
[x,k]=jacobi([7 -2 1 0;1 -9 3 -1;2 0 10 1;1 -1 1 6],[17;13;15;10],[0;0;0;0],1.e-3,30,1)

Ficheiro seidel.m ( Kharab modificado )


iteration method.
ou
[x,k,rerr,Y]=seidel(A,b,x0,tol,itmax,kt)
Os dados sao a matriz n*n e o vector b 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 infinita)
e o numero maximo de iteraoes itmax.
- Se existir kt e kt=1 e fornecida uma tabela com as iteraoes.
Esta versao foi modificada do original (Kharab) vectorizando-a e para
aceitar
parametros de saida.
Fornece a soluao x, obtida em k iteraoes, o rerr e a
tabela Y com todas as iteraoes (coluna 1 = vector x0)e na ultima
linha ||xi-x(i-1)||
EXEMPLO
[x,k]=seidel([7 -2 1 0;1 -9 3 -1;2 0 10 1;1 -1 1 6],[17;13;15;10],[0;0;0;0],1.e-3,30,1)

Anlise Numrica LEC - Help

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)

Potrebbero piacerti anche