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.

For matrix A the only valid values for norm are ±2, ±1, ± inf, and ‘fro’ (or ‘f’) Thus,<br />

⎧ �<br />

maxi j<br />

⎪⎨<br />

�A� =<br />

⎪⎩<br />

|aij| ord = inf<br />

�<br />

mini j |aij| ord = −inf<br />

�<br />

maxj i |aij|<br />

�<br />

ord = 1<br />

minj i |aij| ord = −1<br />

max σi ord = 2<br />

min σi �<br />

ord = −2<br />

trace (AHA) ord = ’fro’<br />

where σi are the singular values of A .<br />

Solving linear least-squares problems and pseudo-inverses<br />

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

Linear least-squares problems occur in many branches of applied mathematics. In this problem a set of linear scaling<br />

coefficients is sought that allow a model to fit data. In particular it is assumed that data yi is related to data xi through<br />

a set of coefficients cj and model functions fj (xi) via the model<br />

yi = �<br />

cjfj (xi) + ɛi<br />

j<br />

where ɛi represents uncertainty in the data. The strategy of least squares is to pick the coefficients cj to minimize<br />

J (c) = �<br />

�<br />

�<br />

�<br />

�<br />

�<br />

� yi − �<br />

Theoretically, a global minimum will occur when<br />

∂J<br />

= 0 = �<br />

⎛<br />

⎝yi − �<br />

or<br />

where<br />

When A H A is invertible, then<br />

∂c ∗ n<br />

�<br />

j<br />

cj<br />

�<br />

i<br />

i<br />

i<br />

j<br />

j<br />

cjfj (xi)<br />

⎞<br />

�2<br />

�<br />

�<br />

�<br />

� .<br />

�<br />

cjfj (xi) ⎠ (−f ∗ n (xi))<br />

fj (xi) f ∗ n (xi) = �<br />

yif ∗ n (xi)<br />

A H Ac = A H y<br />

{A} ij = fj (xi) .<br />

c = � A H A �−1 A H y = A † y<br />

where A † is called the pseudo-inverse of A. Notice that using this definition of A the model can be written<br />

y = Ac + ɛ.<br />

The command linalg.lstsq will solve the linear least squares problem for c given A and y . In addition<br />

linalg.pinv or linalg.pinv2 (uses a different method based on singular value decomposition) will find A †<br />

given A.<br />

The following example and figure demonstrate the use of linalg.lstsq and linalg.pinv for solving a datafitting<br />

problem. The data shown below were generated using the model:<br />

yi = c1e −xi + c2xi<br />

where xi = 0.1i for i = 1 . . . 10 , c1 = 5 , and c2 = 4. Noise is added to yi and the coefficients c1 and c2 are estimated<br />

using linear least squares.<br />

1.8. Linear Algebra 41<br />

i

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

Saved successfully!

Ooh no, something went wrong!