15.12.2012 Views

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

print U<br />

[[-0.70710678 -0.70710678]<br />

[-0.70710678 0.70710678]]<br />

>>> print Sig<br />

[[ 5.19615242 0. 0. ]<br />

[ 0. 1. 0. ]]<br />

>>> print Vh<br />

[[ -2.72165527e-01 -6.80413817e-01 -6.80413817e-01]<br />

[ -6.18652536e-16 -7.07106781e-01 7.07106781e-01]<br />

[ -9.62250449e-01 1.92450090e-01 1.92450090e-01]]<br />

>>> print A<br />

[[1 3 2]<br />

[1 2 3]]<br />

>>> print U*Sig*Vh<br />

[[ 1. 3. 2.]<br />

[ 1. 2. 3.]]<br />

LU decomposition<br />

The LU decompostion finds a representation for the M × N matrix A as<br />

A = PLU<br />

SciPy Reference Guide, Release 0.8.dev<br />

where P is an M × M permutation matrix (a permutation of the rows of the identity matrix), L is in M × K lower<br />

triangular or trapezoidal matrix ( K = min (M, N) ) with unit-diagonal, and U is an upper triangular or trapezoidal<br />

matrix. The SciPy command for this decomposition is linalg.lu .<br />

Such a decomposition is often useful for solving many simultaneous equations where the left-hand-side does not<br />

change but the right hand side does. For example, suppose we are going to solve<br />

Axi = bi<br />

for many different bi . The LU decomposition allows this to be written as<br />

PLUxi = bi.<br />

Because L is lower-triangular, the equation can be solved for Uxi and finally xi very rapidly using forward- and<br />

back-substitution. An initial time spent factoring A allows for very rapid solution of similar systems of equations<br />

in the future. If the intent for performing LU decomposition is for solving linear systems then the command<br />

linalg.lu_factor should be used followed by repeated applications of the command linalg.lu_solve to<br />

solve the system for each new right-hand-side.<br />

Cholesky decomposition<br />

Cholesky decomposition is a special case of LU decomposition applicable to Hermitian positive definite matrices.<br />

When A = A H and x H Ax ≥ 0 for all x , then decompositions of A can be found so that<br />

A = U H U<br />

A = LL H<br />

where L is lower-triangular and U is upper triangular. Notice that L = U H . The command linagl.cholesky<br />

computes the cholesky factorization. For using cholesky factorization to solve systems of equations there are also<br />

linalg.cho_factor and linalg.cho_solve routines that work similarly to their LU decomposition counterparts.<br />

1.8. Linear Algebra 45

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!