Linear Algebra and the C Language/a0d6


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as:  c00b.c                    */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define   RCA        RC3
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
{
double **A        = rsymmetric_mR(            i_mR(RCA,RCA),9.);
double **EVector  =     eigs_V_mR(A,          i_mR(RCA,RCA));
double **EVectorT =  transpose_mR(EVector,    i_mR(RCA,RCA)); 
double **T        =        mul_mR(EVectorT,A, i_mR(RCA,RCA));        
double **EValue   =        mul_mR(T,EVector,  i_mR(RCA,RCA));

  clrscrn();
  
  printf(" A:");
  p_mR(A,S10,P2,C6);  
    
/* EValue = EVectorT A EVector      */ 
/*      A = EVector EValue EVectorT */ 
  mul_mR(EVector,EValue,T);
  mul_mR(T,EVectorT,A);  

  printf(" EVector:");  
  p_mR(EVector,S10,P4,C6);
  
  printf(" EValue:");  
  p_mR(EValue,S10,P4,C6);
    
  printf(" A = EVector EValue EVectorT");  
  p_mR(A,S10,P2,C6);     
   
  f_mR(A);
    
  f_mR(EVector);
  f_mR(EVectorT);
  
  f_mR(EValue);  
     
  f_mR(T);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  fun();

} while(stop_w());

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

Screen output example:

                                                                                       
 A:
     +2.00      -3.00      +6.00 
     -3.00      +3.00      +4.00 
     +6.00      +4.00      -7.00 

 EVector:
   -0.4391    +0.7783    +0.4489 
   -0.3191    -0.6021    +0.7318 
   +0.8399    +0.1781    +0.5127 

 EValue:
  -11.6566    +0.0000    -0.0000 
   +0.0000    +5.6943    +0.0000 
   -0.0000    +0.0000    +3.9623 

 A = EVector EValue EVectorT
     +2.00      -3.00      +6.00 
     -3.00      +3.00      +4.00 
     +6.00      +4.00      -7.00 


 Press   return to continue
 Press X return to stop