Fix occasional warning in ok_status()
[Math-GSL.git] / examples / matrix / nonsymmetric_eigen
blob83e1e26150f0dfa61798125b51f7afca51f6202a
1 #!/usr/bin/perl -w
2 use Math::GSL::Matrix;
3 use strict;
4 my $matrix = Math::GSL::Matrix->new(2,2)
5 ->set_row(0, [0,-1] )
6 ->set_row(1, [1, 0] );
7 print <<STUFF;
8 Finding eigenvalue/eigenvectors for
9 [ 0 -1 ]
10 [ 1 0 ]
11 STUFF
13 # this actually calculates the eigenvalues and eigenvectors and returns
14 # an array reference of eigenvalues (scalars which may be Math::Complex objects)
15 # and an array reference of Math::GSL::VectorComplex objects
16 my ($eigenvalues, $eigenvectors) = $matrix->eigenpair;
17 my ($eig1,$eig2) = @$eigenvalues;
18 my ($u,$v) = @$eigenvectors;
19 my ($u1,$u2) = $u->as_list;
20 my ($v1,$v2) = $v->as_list;
22 print <<ANSWER;
24 Eigenvectors:
26 u = ($u1,$u2)
27 v = ($v1,$v2)
29 Eigenvalues:
31 lambda_0 = $eig1
32 lambda_1 = $eig2
34 ANSWER