Linear Algebra and the C Language/a03t


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as:   c02d.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   = Pinv_Cn_mR(A,       i_mR(CA,RA),FACTOR_E);   
double **APinv  =     mul_mR(A,Pinv,  i_mR(RA,RA));    
double **APinvA =     mul_mR(APinv,A, i_mR(RA,CA));

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

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

  printf(" A*Pinv*A:"); 
  p_mR(APinvA, S7,P2,C10);
  
  printf(" A:");
  p_mR(A, S7,P2,C7);    
  
  f_mR(A); 
  f_mR(Pinv); 
  f_mR(APinv); 
  f_mR(APinvA);  
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  
  fun();

} while(stop_w());

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

Screen output example:

 A :
  -7.00   +4.00   -1.00   -9.00   -4.00 
  -5.00   -1.00   -1.00   +3.00   +9.00 
  -6.00   -4.00   +3.00   +6.00   +3.00 

 PseudoInverse = V * invS_T * U_T 
 -6.4826e-02  -1.1344e-02  -7.4768e-02 
 +1.6368e-02  +2.9927e-02  -5.2553e-02 
 +1.4319e-03  -5.0404e-02  +6.5021e-02 
 -4.5134e-02  -2.0950e-02  +5.3315e-02 
 -1.8992e-02  +1.0952e-01  -5.7924e-02 

 Press return to continue. 


 A*Pinv:
  +1.00   +0.00   +0.00 
  -0.00   +1.00   -0.00 
  +0.00   +0.00   +1.00 

 A*Pinv*A:
  -7.00   +4.00   -1.00   -9.00   -4.00 
  -5.00   -1.00   -1.00   +3.00   +9.00 
  -6.00   -4.00   +3.00   +6.00   +3.00 

 A :
  -7.00   +4.00   -1.00   -9.00   -4.00 
  -5.00   -1.00   -1.00   +3.00   +9.00 
  -6.00   -4.00   +3.00   +6.00   +3.00 


 Press   return to continue
 Press X return to stop