Linear Algebra and the C Language/a03u


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c02e.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define   RA R3
#define   CA C5
/* ------------------------------------ */
#define FACTOR_E        +1.E-0         
/* ------------------------------------ */
void fun(void)
{
double **A         = r_mR(i_mR(RA,CA),9);
double **Pinv      =      i_mR(CA,RA);     
double **PinvA     =      i_mR(CA,CA);    
double **PinvAPinv =      i_mR(CA,RA);

  clrscrn();
  printf(" A :");
  p_mR(A,S7,P2,C7);   
  
  printf(" PseudoInverse = V * invS_T * U_T ");
  Pinv_Cn_mR(A,Pinv,FACTOR_E); 
  pE_mR(Pinv,S12,P4,C10);
  stop();

  clrscrn();  
  printf(" Pinv*A:");
  mul_mR(Pinv,A,PinvA); 
  p_mR(PinvA,S7,P2,C10); 

  printf(" Pinv*A*Pinv:");
  mul_mR(PinvA,Pinv,PinvAPinv); 
  p_mR(PinvAPinv,S7,P4,C10);
  
  printf(" Pinv :");
  p_mR(Pinv,S7,P4,C7);    
  
  f_mR(A); 
  f_mR(Pinv); 
  f_mR(PinvA); 
  f_mR(PinvAPinv);  
  
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  
  fun();

} while(stop_w());

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


Screen output example:

 A :
  -5.00   +7.00   -6.00   +8.00   -5.00 
  -1.00   +5.00   -4.00   +7.00   +6.00 
  -4.00   -8.00   -8.00   -4.00   +6.00 

 PseudoInverse = V * invS_T * U_T 
 -4.4324e-02  +2.4551e-02  -3.2216e-02 
 +1.0385e-02  +3.3234e-02  -3.8845e-02 
 -4.3724e-02  +1.1272e-03  -5.1993e-02 
 +1.5714e-02  +4.4527e-02  -1.7308e-02 
 -6.3525e-02  +9.1867e-02  +1.2532e-02 

 Press return to continue. 


 Pinv*A:
  +0.33   +0.07   +0.43   -0.05   +0.18 
  +0.07   +0.55   +0.12   +0.47   -0.09 
  +0.43   +0.12   +0.67   -0.13   -0.09 
  -0.05   +0.47   -0.13   +0.51   +0.08 
  +0.18   -0.09   -0.09   +0.08   +0.94 

 Pinv*A*Pinv:
-0.0443 +0.0246 -0.0322 
+0.0104 +0.0332 -0.0388 
-0.0437 +0.0011 -0.0520 
+0.0157 +0.0445 -0.0173 
-0.0635 +0.0919 +0.0125 

 Pinv :
-0.0443 +0.0246 -0.0322 
+0.0104 +0.0332 -0.0388 
-0.0437 +0.0011 -0.0520 
+0.0157 +0.0445 -0.0173 
-0.0635 +0.0919 +0.0125 


 Press   return to continue
 Press X return to stop