Aller au contenu

Mathc matrices/03c

Un livre de Wikilivres.


Application

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

c00b.c
/* ------------------------------------ */
/*  Save as :   c00b.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */     
#define RCA          RC5  
/* ------------------------------------ */ 
void fun(void)
{     
/* Choose your Eigenvalues */                       
double d[RCA*RCA] ={   
  +.001,  +0,  +0,  +0,  +0,  
  +0,     +2,  +0,  +0,  +0,   
  +0,     +0,  +3,  +0,  +0,
  +0,     +0,  +0,  +4,  +0,
  +0,     +0,  +0,  +0,  +500    
};

double **D         =         ca_A_mR(d,      i_mR(RCA,RCA));                       
double **A         = rdefpos_diag_mR(D,      i_mR(RCA,RCA),9);
double **invA      =        invgj_mR(A,      i_mR(RCA,RCA));
double **AinvA     =          mul_mR(A,invA, i_mR(RCA,RCA));
double **EigsValue =         eigs_mR(A,      i_mR(RCA,C1));

double cond        = EigsValue[R1][C1] / EigsValue[RCA][C1];
                  /* maxi value          mini value       */
  clrscrn();
  printf(" Copy/Paste into the octave windows \n\n");
  p_Octave_mR(A,"a",P12);
  printf(" EigenValues  = eigs (a,%d) \n\n",RCA);   
    
  printf(" EigenValues:       cond = EvalueMax / EvalueMin = %.e",cond);
  p_mR(EigsValue, S13,P8,C1); 
 
  stop();

  clrscrn();
  printf(" invA:");
  p_mR(invA, S13,P4,C5); 
  
  printf(" cond = EvalueMax / EvalueMin = %.e\n\n"
         " Id == A invA:",cond);
  p_mR(AinvA, S13,P12,C5);      
             
  f_mR(A);
  f_mR(D);
  f_mR(invA);
  f_mR(AinvA);
  f_mR(EigsValue); 
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
  
  do
        fun();

  while(stop_w());       

  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Avec , de petites erreurs apparaissent dans les calculs de l'inverse.
Exemple de sortie écran :
 Copy/Paste into the octave windows 

 a=[
+207.238502532924,+17.657148482125,+158.877070899710,-155.528675242538,-101.587799619069;
+17.657148482125,+3.739929299800,+14.526155839131,-13.802249972067,-10.407107725072;
+158.877070899710,+14.526155839131,+126.331091603141,-120.735412584751,-78.710486107231;
-155.528675242538,-13.802249972067,-120.735412584751,+119.863709051142,+75.378872710302;
-101.587799619069,-10.407107725072,-78.710486107231,+75.378872710302,+51.827767512993]

 EigenValues  = eigs (a,5) 

 EigenValues:       cond = EvalueMax / EvalueMin = 5e+05
+500.00000000 
  +4.00000000 
  +3.00000000 
  +2.00000000 
  +0.00100000 

 Press return to continue. 


 invA:
    +184.0435     +229.7927      +45.8675     +138.0048     +275.8301 
    +229.7927     +287.6265      +57.3804     +172.2850     +344.7436 
     +45.8675      +57.3804      +11.7856      +34.5960      +69.0091 
    +138.0048     +172.2850      +34.5960     +103.7074     +206.8063 
    +275.8301     +344.7436      +69.0091     +206.8063     +413.9223 

 cond = EvalueMax / EvalueMin = 5e+05

 A invA:
+1.000000000007 +0.000000000000 +0.000000000000 +0.000000000000 +0.000000000007 
+0.000000000000 +1.000000000001 +0.000000000000 +0.000000000000 +0.000000000000 
+0.000000000000 +0.000000000015 +1.000000000001 +0.000000000002 +0.000000000004 
+0.000000000004 -0.000000000007 -0.000000000002 +0.999999999996 -0.000000000007 
+0.000000000002 -0.000000000004 -0.000000000000 +0.000000000000 +1.000000000004 


 Press   return to continue
 Press X return to stop