Aller au contenu

Mathc matrices/c29a2

Un livre de Wikilivres.


La décomposition spectral

Installer et compiler ces fichiers dans votre répertoire de travail.

c00c.c
/* ------------------------------------ */
/*  Save as:  c00c.c                    */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define ARRAY   A3
/* ------------------------------------ */
#define RC     RC3
/* ------------------------------------ */
void fun(void)
{
double **A         = rsymmetric_mR(        i_mR(RC,RC),999);
double **AEVect    =     eigs_V_mR(A,      i_mR(RC,RC));
double **InvAEVect =  transpose_mR(AEVect, i_mR(RC,RC));
double **AEValue   =       eigs_mR(A,      i_mR(RC,C1)); 

double **T         =                       i_mR(RC,RC);
double **a         =                       i_mR(RC,RC);

double **b    [ARRAY];
double **r    [ARRAY];
double **br   [ARRAY];
double **EVabr[ARRAY];

int i;

  for(i=A0; i<ARRAY; i++)
     {
      b[i]     =  c_c_mR(   AEVect,i+C1,           i_mR(RC,C1),C1);
      r[i]     =  c_r_mR(InvAEVect,i+R1,           i_mR(R1,RC),R1);
      
      br[i]    =  mul_mR(b[i],r[i],                i_mR(RC,RC));
      
      EVabr[i] = smul_mR(AEValue[i+R1][C1], br[i], i_mR(RC,RC));  
      }
      
  clrscrn();
  printf(" A:");
  p_mR(A, S10,P4,C6);

  printf(" AEVect:        Eingvectors of A");
  p_mR(AEVect, S10,P4,C6);
   
  printf(" AEValue:      Eignvalues of A");
  p_mR(AEValue, S10,P4,C6);
  stop();

  clrscrn(); 
  printf(" A:");
  p_mR(A, S10,P4,C6);
  
  add_mR(EVabr[0], EVabr[1], T); 
  add_mR(       T, EVabr[2], a);  
  printf(" E1*b1r1 + E2*b2r2 + E3*b3r3 = A");
  p_mR(a, S10,P4,C6);
   
  f_mR(A);
  f_mR(AEVect);
  f_mR(InvAEVect);
  f_mR(AEValue);
      
  f_mR(T);
  
  for(i=A0; i<ARRAY; i++)
     {
       f_mR(    b[i]);
       f_mR(    r[i]);
       f_mR(   br[i]); 
       f_mR(EVabr[i]);                   
     }   
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
 fun();

} while(stop_w());

  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Nous voyons une des propriètés de la décomposition spectral:

 E1*b1r1 + E2*b2r2 + E3*b3r3 = A
 
E1 est la première valeur propre, E2 la deuxième et E3 la troisième.

b1r1 est obtenue en multipliant la première colonne de la matrice des vecteurs propres par la première ligne de la matrice inverse des vecteurs propres.
Exemple de sortie écran :
A:
 +333.0000  -413.0000  +924.0000 
 -413.0000  -118.0000  +712.0000 
 +924.0000  +712.0000  +870.0000 

 AEVect:        Eingvectors of A
   +0.5196    +0.5509    -0.6531 
   +0.2137    +0.6564    +0.7236 
   +0.8273    -0.5155    +0.2233 

 AEValue:      Eignvalues of A
+1634.2674 
-1023.8379 
 +474.5705 

 Press return to continue. 


 A:
 +333.0000  -413.0000  +924.0000 
 -413.0000  -118.0000  +712.0000 
 +924.0000  +712.0000  +870.0000 

 E1*b1r1 + E2*b2r2 + E3*b3r3 = A
 +333.0000  -413.0000  +924.0000 
 -413.0000  -118.0000  +712.0000 
 +924.0000  +712.0000  +870.0000 


 Press   return to continue
 Press X return to stop