Linear Algebra and the C Language/a0mk


Install and compile this file in your working directory.

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

int rA = rsize_R(A);
int cA = csize_R(A);

  clrscrn();
  printf(" A:");
  p_mR(A,S5,P0,C6);  
  
  printf(" Copy/Paste into the octave windows \n\n\n");
  p_Octave_mR(A,"a",P0);
  printf(" SvdValue = svd (a,10)\n\n\n");
  stop();

  clrscrn();  
  
  /* The algorithm of the function svds_mR(); works */ 
  /* when the number of rows of A or A_T is greater */
  /* than or equal to the number of columns.        */
  
  /* It therefore chooses to work either directly   */
  /* on the matrix A or on its transpose A_T.       */
  
  if( rA>=cA)
     {
	  SvdValue   = i_mR(cA,C1);
      svds_mR(A,SvdValue);
     }
  else
     {
	  SvdValue   = i_mR(rA,C1);
      svds_mR(A_T,SvdValue);
     }
     
  printf(" (A_t A) and (A A_T) are generally             \n" 
         " not the same size. One therefore has          \n"
         " more eigenvalues ​​than the other.              \n"
         " The additional eigenvalues ​​are always zero. \n\n"
         " A:");
  p_mR(A,S5,P0,C6); 
  printf(" SvdValue:");
  p_mR(SvdValue,S13,P4,C1);     
    
  f_mR(A);
  f_mR(A_T);
  f_mR(SvdValue);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

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

} while(stop_w());

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

Screen output example:

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

 Copy/Paste into the octave windows 


 a=[
+4,-5,+2,-5,+2;
+9,-1,+7,-1,-8;
-4,-9,+7,-4,-8;
-2,-1,-4,-8,+6;
-3,-7,-7,-4,-3]

 SvdValue = svd (a,10)


 Press return to continue. 


 (A_t A) and (A A_T) are generally   
 not the same size. One therefore has
 more eigenvalues ​​than the other.    
 The additional eigenvalues ​​are always zero.

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

 SvdValue:
     +18.4228 
     +15.7615 
     +10.1722 
      +6.8928 
      +3.1923 


 Press   return to continue
 Press X return to stop