Linear Algebra and the C Language/a0e2


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00e.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define   RB R5
#define   CB C2
/* ------------------------------------ */
int main(void)
{
double b[RB*CB]={
-1.00,-5.00,
-1.00,+6.00,
-2.00,+8.00,
+3.00,+1.00,
+4.00,-5.00
};

double **B   =      ca_A_mR(b,  i_mR(RB,CB));
double **BT  = transpose_mR(B,  i_mR(CB,RB));

double **U   =  svd_U_Rn_mR(BT, i_mR(RB,CB));
double **UT  = transpose_mR(U,  i_mR(CB,RB));             
double **UUT =                  i_mR(RB,RB);
double **UTU =                  i_mR(CB,CB);
double **V   =  svd_V_Rn_mR(BT, i_mR(CB,CB)); 
double **VT  = transpose_mR(V,  i_mR(CB,CB)); 
double **VVT =                  i_mR(CB,CB); 

  
  clrscrn();  
  printf(" Copy/Paste into the octave windows \n\n");
  p_Octave_mR(B,"B",P2);
  printf(" [U, S, V] =svd (B,10)\n\n");

  printf(" U :");
  p_mR(U, S5,P5,C10);   
             
  printf(" V:");
  p_mR(V,S5,P5,C10); 
  stop();  

  clrscrn();  
  printf(" Copy/Paste into the octave windows\n");
  p_Octave_mR(B,"B",P2);
  printf(" [U, S, V] =svd (B,10);\n"
         " U*U'\n"
         " U'*U\n\n");
         
  printf(" U UT :");
  p_mR( mul_mR(U,UT,UUT) ,S10,P3,C10);
  
  printf(" UT U :");
  p_mR( mul_mR(UT,U,UTU) ,S10,P3,C10);
  stop();  

  clrscrn();  
  printf(" Copy/Paste into the octave windows \n\n");
  p_Octave_mR(B,"B",P2);
  printf(" [U, S, V] =svd (B,10);\n"
         " V*V'\n"
         " V'*V\n\n");   
                
  printf(" V VT :");
  p_mR( mul_mR(V,VT,VVT) ,S10,P3,C10); 
          
  printf(" VT V  :");
  p_mR(mul_mR(VT,V,VVT) ,S10,P3,C10); 
  stop();
          
  f_mR(B);
  f_mR(BT);
  f_mR(U); 
  f_mR(UT);
  f_mR(UUT);
  f_mR(UTU);
  f_mR(V); 
  f_mR(VT);
  f_mR(VVT);
    
  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */


Screen output example:

                                                                                       
 Copy/Paste into the octave windows 

 B=[
-1.00,-5.00;
-1.00,+6.00;
-2.00,+8.00;
+3.00,+1.00;
+4.00,-5.00]

 [U, S, V] =svd (B,10)

 U :
-0.36211 -0.47752 
+0.47888 +0.11985 
+0.65194 +0.02248 
+0.01598 +0.67227 
-0.46289 +0.55242 

 V:
-0.25493 +0.96696 
+0.96696 +0.25493 

 Press return to continue. 


 Copy/Paste into the octave windows
 B=[
-1.00,-5.00;
-1.00,+6.00;
-2.00,+8.00;
+3.00,+1.00;
+4.00,-5.00]

 [U, S, V] =svd (B,10);
 U*U'
 U'*U

 U UT :
    +0.359     -0.231     -0.247     -0.327     -0.096 
    -0.231     +0.244     +0.315     +0.088     -0.155 
    -0.247     +0.315     +0.426     +0.026     -0.289 
    -0.327     +0.088     +0.026     +0.452     +0.364 
    -0.096     -0.155     -0.289     +0.364     +0.519 

 UT U :
    +1.000     -0.000 
    -0.000     +1.000 

 Press return to continue. 


 Copy/Paste into the octave windows 

 B=[
-1.00,-5.00;
-1.00,+6.00;
-2.00,+8.00;
+3.00,+1.00;
+4.00,-5.00]

 [U, S, V] =svd (B,10);
 V*V'
 V'*V

 V VT :
    +1.000     -0.000 
    -0.000     +1.000 

 VT V  :
    +1.000     -0.000 
    -0.000     +1.000 

 Press return to continue.