Linear Algebra and the C Language/a0dn


Install and compile this file in your working directory.

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

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

double **S   =      svds_mR(B,   i_mR(CB,C1));   
double **U   =  svd_U_Rn_mR(B_T, i_mR(RB,CB));     
double **V   =  svd_V_Rn_mR(B_T, 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\n");
  stop();

  clrscrn(); 
  printf(" U :");
  p_mR(U,S5,P5,C10);   
    
  printf(" S :");
  p_mR(S,S5,P5,C10);
   
  printf(" V:");
  p_mR(V,S5,P5,C10);
  stop();  
    
  f_mR(B_T);
  f_mR(B);
  f_mR(S); 
  f_mR(U);
  f_mR(V); 

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


Screen output example:

                                                                                       
 Copy/Paste into the octave windows 


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

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


 Press return to continue. 


 U :
-0.28974 -0.16712 
-0.38334 +0.86361 
+0.84140 +0.40785 
+0.24728 -0.24477 

 S :
+13.48055 
+9.91336 

 V:
-0.37484 +0.92709 
+0.92709 +0.37484 

 Press return to continue.