Linear Algebra and the C Language/a0dm


Install and compile this file in your working directory.

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

double **S   =      svds_mR(B,   i_mR(c,C1));  
double **U   =  svd_U_Rn_mR(B_T, i_mR(r,c)); 
double **V   =  svd_V_Rn_mR(B_T, i_mR(c,c));  

  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);  
    
  f_mR(B_T);
  f_mR(B);
  f_mR(S); 
  f_mR(U);
  f_mR(V); 
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

int i;

do
{
  i = rp_I(R3)+R1;
  
  fun(i+R2,i);

} while(stop_w());

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


Screen output example:

                                                                                       
 Copy/Paste into the octave windows 


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

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


 Press return to continue. 


 U :
+0.00879 +0.69504 +0.06967 +0.58697 
-0.06349 -0.06775 +0.77183 -0.14366 
+0.63192 +0.50834 -0.14278 -0.48383 
+0.39632 -0.41813 -0.38186 +0.43279 
-0.51742 +0.11520 -0.46937 -0.40696 
-0.41446 +0.25653 -0.11362 +0.21868 

 S :
+23.78203 
+14.70115 
+10.29890 
+5.12091 

 V:
-0.01987 +0.82347 -0.43041 -0.36912 
+0.64264 -0.03072 +0.44547 -0.62259 
-0.47650 +0.41267 +0.77515 +0.04242 
+0.59964 +0.38814 +0.12428 +0.68872 


 Press   return to continue
 Press X return to stop