Linear Algebra and the C Language/a0mi


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00c.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r,int rn)
{
double **A         =         r_mR(       i_mR(r+rn,r),9);
double **A_T       = transpose_mR(A,     i_mR(r,r+rn));
double **A_TA      =       mul_mR(A_T,A, i_mR(r,r)); 

double **EigsValue =      eigs_mR(A_TA,   i_mR(r,C1));

  clrscrn();
  printf(" A :");
  p_mR(A,S5,P0,C12); 
   
  printf(" A_T :");
  p_mR(A_T,S5,P0,C12);
  stop();
  
  clrscrn();
  printf(" Let's calculate the eigenvalues ​​of an A_TA matrix.\n"
         " The eigenvalues ​​of this A_TA matrix\n"
         " are always positive.\n\n" 
         " A_TA:");   
  p_mR(A_TA,S5,P0,C12);   
  
  printf(" EigenValues A_TA:");
  p_mR(EigsValue,S13,P4,C1);
         
  f_mR(A);
  f_mR(A_T);
  f_mR(A_TA);
  f_mR(EigsValue);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  fun(rp_I(R6),rp_I(R6));

} while(stop_w());

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

Screen output example:

                                                                                       
 A :
   -9    +7    +1 
   -2    -6    +6 
   -1    +6    +5 
   -4    +6    -1 
   +2    +4    +5 

 A_T :
   -9    -2    -1    -4    +2 
   +7    -6    +6    +6    +4 
   +1    +6    +5    -1    +5 

 Press return to continue. 


 Let's calculate the eigenvalues ​​of an A_TA matrix.
 The eigenvalues ​​of this A_TA matrix
 are always positive.

 A_TA:
 +106   -73   -12 
  -73  +173   +15 
  -12   +15   +88 

 EigenValues A_TA:
    +222.5332 
     +85.4368 
     +59.0301 


 Press   return to continue
 Press X return to stop