Linear Algebra and the C Language/a0dc


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00c.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r)
{
double **A            = rsymmetric_mR(    i_mR(r,r),9.);
double **EigsValue    =       eigs_mR(A,  i_mR(r,C1));
double **Inv          =        inv_mR(A,  i_mR(r,r));
double **EigsValueInv =       eigs_mR(Inv,i_mR(r,C1));

int    i = 0;
int    j = 0;

  clrscrn();

  printf(" A :");
  p_mR(A,S2,P0,C6);
  
  printf(" inv(A)");
  pE_mR(Inv,S12,P4,C5);
  stop();

  clrscrn();
  printf(" EigsValue of A :");
  p_mR(EigsValue,S13,P6,C1); 
    
  printf(" EigsValue of invA :");
  p_mR(EigsValueInv,S13,P6,C1);  
  
  for(i=1,j=r; i<=r; i++,j--)
       
       printf(" EigsValue[%d]*EigsValueInv[%d]: %.3f    \n",
           i,j,EigsValue[i][C1]*EigsValueInv[j][C1]);      
           
  f_mR(EigsValueInv);  
  f_mR(EigsValue);  
  f_mR(Inv);
  f_mR(A);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
do
{
  fun(rp_I(RC4)+C1);

} while(stop_w());


  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */


Screen output example:

                                                                                       
 A :
-2 +6 -1 
+6 +7 -6 
-1 -6 +6 

 inv(A)
 -3.6810e-02  +1.8405e-01  +1.7791e-01 
 +1.8405e-01  +7.9755e-02  +1.1043e-01 
 +1.7791e-01  +1.1043e-01  +3.0675e-01 

 Press return to continue. 


 EigsValue of A :
   +14.204888 
    -5.349810 
    +2.144922 

 EigsValue of invA :
    +0.466217 
    -0.186923 
    +0.070398 

 EigsValue[1]*EigsValueInv[3]: 1.000    
 EigsValue[2]*EigsValueInv[2]: 1.000    
 EigsValue[3]*EigsValueInv[1]: 1.000    

 Press   return to continue
 Press X return to stop