Linear Algebra and the C Language/a0e3


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00e.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define   RB R3
#define   CB C4
/* ------------------------------------ */
void fun(void)
{
double **B   =         r_mR( i_mR(RB,CB),9.);

double **U   =  svd_U_Cn_mR(B,i_mR(RB,RB));    
double **UT  =  transpose_mR(U,i_mR(RB,RB));
double **UUT =                 i_mR(RB,RB);

double **V   =  svd_V_Cn_mR(B,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\n");
  p_Octave_mR(B,"B",P2);
  printf(" [U, S, V] =svd (B,10)\n\n"
         " U*U'\n"
         " V*V'\n\n");

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

  clrscrn();        
  printf(" U UT :");
  p_mR( mul_mR(U,UT,UUT) ,S10,P3,C10); 
          
  printf(" V VT :");
  p_mR(mul_mR(V,VT,VVT) ,S10,P3,C10); 

  f_mR(B);
  f_mR(U);
  f_mR(UT);
  f_mR(UUT);
  f_mR(V); 
  f_mR(VT);
  f_mR(VVT);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  fun();

} while(stop_w());

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


Screen output example:

                                                                                       
 Copy/Paste into the octave windows 


 B=[
-7.00,+9.00,+9.00,+1.00;
+7.00,+8.00,+9.00,-4.00;
-4.00,+1.00,+8.00,+6.00]

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

 U*U'
 V*V'

 U :
+0.71582 -0.33700 -0.61158 
+0.56572 +0.79331 +0.22501 
+0.40935 -0.50705 +0.75851 

 V:
-0.14231 +0.81264 +0.49440 +0.27372 
+0.60233 +0.22943 -0.51606 +0.56413 
+0.78398 +0.00412 +0.45355 -0.42385 
+0.04813 -0.53568 +0.53248 +0.65360 

 Press return to continue. 


 U UT :
    +1.000     +0.000     -0.000 
    +0.000     +1.000     +0.000 
    -0.000     +0.000     +1.000 

 V VT :
    +1.000     +0.000     +0.000     +0.000 
    +0.000     +1.000     +0.000     -0.000 
    +0.000     +0.000     +1.000     -0.000 
    +0.000     -0.000     -0.000     +1.000 


 Press   return to continue
 Press X return to stop