Linear Algebra and the C Language/a0n6


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as:  c00f.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]*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**2:");
  pow_mR(2, A, T);
  p_mR(T, S10,P0,C6);
  
  add_mR(EVabr[0], EVabr[1], T); 
  add_mR(       T, EVabr[2], a);  
  printf(" We can calculate the nth power of A\n"
         " by simply taking the nth power of  \n"
         " each of the eigenvalues.     \n\n\n\n"
         " E1**2 b1r1 + E2**2 b2r2 + E3**2 b3r3 = A**2");
  p_mR(a, S10,P0,C6);
   
  f_mR(A);
  f_mR(AEVect);
  f_mR(InvAEVect);
  f_mR(AEValue); 
  
  f_mR(T);
  f_mR(a);
  
  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;
}
/* ------------------------------------ */
/* ------------------------------------ */
A property of spectral decomposition:

 E1**2 * b1r1 + E2**2 * b2r2 + E3**2 * b3r3 = A**2
 E1**3 * b1r1 + E2**3 * b2r2 + E3**3 * b3r3 = A**3
       ...
 E1**n * b1r1 + E2**n * b2r2 + E3**n * b3r3 = A**n

We can calculate the nth power of A by simply taking the nth power of each of the eigenvalues.

  b: The columns of the eigenvectors of A
  r: The rows of eigenvectors of the inverse of A
  E: The eignvalues of A.  
  
  b1r1 is obtained by multiplying the first column of the eigenvector of A by the first row of the eigenvector of the inverse of A.

Screen output example:

                                                                                       
 A:
  +28.0000  +729.0000   -82.0000 
 +729.0000  +419.0000  -499.0000 
  -82.0000  -499.0000  +507.0000 

 AEVect:        Eingvectors of A
   +0.4597    +0.7274    +0.5094 
   +0.7149    -0.6435    +0.2737 
   -0.5269    -0.2383    +0.8158 

 AEValue:      Eignvalues of A
+1255.5856 
 -589.9704 
 +288.3848 

 Press return to continue. 


 A**2:
   +538949    +366781    -407641 
   +366781    +956003    -521852 
   -407641    -521852    +512774 

 We can calculate the nth power of A
 by simply taking the nth power of  
 each of the eigenvalues.     



 E1**2 b1r1 + E2**2 b2r2 + E3**2 b3r3 = A**2
   +538949    +366781    -407641 
   +366781    +956003    -521852 
   -407641    -521852    +512774 


 Press   return to continue
 Press X return to stop