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.

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

Trigonometric functions<br />

The trigonometric functions sin , cos , and tan are implemented for matrices in linalg.sinm, linalg.cosm,<br />

and linalg.tanm respectively. The matrix sin and cosine can be defined using Euler’s identity as<br />

The tangent is<br />

and so the matrix tangent is defined as<br />

Hyperbolic trigonometric functions<br />

tan (x) =<br />

sin (A) = ejA − e −jA<br />

2j<br />

cos (A) = ejA + e −jA<br />

sin (x)<br />

cos (x) = [cos (x)]−1 sin (x)<br />

2<br />

[cos (A)] −1 sin (A) .<br />

The hyperbolic trigonemetric functions sinh , cosh , and tanh can also be defined for matrices using the familiar<br />

definitions:<br />

sinh (A) = eA − e −A<br />

2<br />

cosh (A) = eA + e −A<br />

2<br />

tanh (A) = [cosh (A)] −1 sinh (A) .<br />

These matrix functions can be found using linalg.sinhm, linalg.coshm , and linalg.tanhm.<br />

Arbitrary function<br />

Finally, any arbitrary function that takes one complex number and returns a complex number can be called as a matrix<br />

function using the command linalg.funm. This command takes the matrix and an arbitrary Python function. It<br />

then implements an algorithm from Golub and Van Loan’s book “Matrix Computations “to compute function applied<br />

to the matrix using a Schur decomposition. Note that the function needs to accept complex numbers as input in order<br />

to work with this algorithm. For example the following code computes the zeroth-order Bessel function applied to a<br />

matrix.<br />

>>> from <strong>scipy</strong> import special, random, linalg<br />

>>> A = random.rand(3,3)<br />

>>> B = linalg.funm(A,lambda x: special.jv(0,x))<br />

>>> print A<br />

[[ 0.72578091 0.34105276 0.79570345]<br />

[ 0.65767207 0.73855618 0.541453 ]<br />

[ 0.78397086 0.68043507 0.4837898 ]]<br />

>>> print B<br />

[[ 0.72599893 -0.20545711 -0.22721101]<br />

[-0.27426769 0.77255139 -0.23422637]<br />

[-0.27612103 -0.21754832 0.7556849 ]]<br />

>>> print linalg.eigvals(A)<br />

[ 1.91262611+0.j 0.21846476+0.j -0.18296399+0.j]<br />

>>> print special.jv(0, linalg.eigvals(A))<br />

[ 0.27448286+0.j 0.98810383+0.j 0.99164854+0.j]<br />

>>> print linalg.eigvals(B)<br />

[ 0.27448286+0.j 0.98810383+0.j 0.99164854+0.j]<br />

48 Chapter 1. SciPy Tutorial<br />

.

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

Saved successfully!

Ooh no, something went wrong!