1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| use strict;
use warnings;
use Math::MatrixDecomposition::Eigen;
#doc du package : http://search.cpan.org/~ralph/Math-MatrixDecomposition-1.01/lib/Math/MatrixDecomposition/Eigen.pm
#creation d une matrice carree symetrique 3x3
my $A11 = 2.;
my $A12 = 1.;
my $A13 = 5.;
my $A22 = 1.;
my $A23 = 7.;
my $A33 = -1.;
my @A = ($A11,$A12,$A13,$A12,$A22,$A23,$A13,$A23,$A33);
print "\n";
print "matrice :\n";
print " | $A11 $A12 $A13 |\n";
print " A = | $A12 $A22 $A23 |\n";
print " | $A13 $A23 $A33 |\n";
#la methode "decompose" est l action par defaut de "new"
my $eigen = Math::MatrixDecomposition::Eigen->new(\@A);
# => equivalent a :
# my $eigen = Math::MatrixDecomposition::Eigen->new;
# $eigen->decompose(\@A);
my @lambda = $eigen->values;
print "\nValeurs propres :\n";
for(my $i=0; $i<=2; $i++) {
print " > lambda_$i = $lambda[$i]\n";
}
my @vec = $eigen->vectors;
print "\nVecteurs propres :\n";
for(my $i=0; $i<=2; $i++) {
print " > u_$i = @{$vec[$i]}\n";
}
my @A_mat = ([$A11,$A12,$A13],
[$A12,$A22,$A23],
[$A13,$A23,$A33]);
my ($no_lambda, @A_u, @lambda_u);
print "\nVerification (A*u = lambda*u avec u = vecteur propre) :\n";
for(my $no_lambda = 0; $no_lambda<=2; $no_lambda++) {
print " > valeur propre $no_lambda et vecteur propre $no_lambda :\n";
for(my $i=0; $i<=2; $i++) {
$A_u[$i] = 0.;
for(my $j=0; $j<=2; $j++) {
$A_u[$i] += $A_mat[$i][$j]*$vec[$no_lambda][$j];
}
$lambda_u[$i] = $vec[$no_lambda][$i]*$lambda[$no_lambda];
}
print " A*u_$no_lambda = @A_u\n";
print " lambda_$no_lambda*u_$no_lambda = @lambda_u\n";
}
print "\n";
print "Verification (vecteurs propres orthogonaux => u_i.u_j = 0) :\n";
my $prod_scal = 0.;
for(my $i=0; $i<=2; $i++) {
$prod_scal += $vec[0][$i]*$vec[1][$i];
}
print " > produit scalaire u_0.u_1 = $prod_scal\n";
$prod_scal = 0.;
for(my $i=0; $i<=2; $i++) {
$prod_scal += $vec[0][$i]*$vec[2][$i];
}
print " > produit scalaire u_0.u_2 = $prod_scal\n";
$prod_scal = 0.;
for(my $i=0; $i<=2; $i++) {
$prod_scal += $vec[1][$i]*$vec[2][$i];
}
print " > produit scalaire u_1.u_2 = $prod_scal\n";
print "\n"; |
Partager