Linear Algebra and the C Language/a03r


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as:   c02b.c                   */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define   RA R3
#define   CA C5
/* ------------------------------------ */
#define FACTOR_E        +1.E-0         
/* ------------------------------------ */
int main(void)
{
double tA[RA*CA]={
  +8.00,   -5.00,   +1.00,   +3.00,   +8.00, 
  -2.00,   +6.00,   -2.00,   -8.00,   -2.00, 
  +3.00,   -9.00,   +9.00,   +7.00,   -7.00  
};

double **A    =    ca_A_mR(tA,     i_mR(RA,CA));
double **Pinv = Pinv_Cn_mR(A,      i_mR(CA,RA),FACTOR_E);     
double **Ide  =     mul_mR(A,Pinv, i_mR(RA,RA));   

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

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

Screen output example:

 A :
  +8.00   -5.00   +1.00   +3.00   +8.00 
  -2.00   +6.00   -2.00   -8.00   -2.00 
  +3.00   -9.00   +9.00   +7.00   -7.00 

 PseudoInverse = V * invS_T * U_T 
 +8.9736e-02  +9.4303e-02  +3.8876e-02 
 -1.6303e-02  +1.4763e-02  -2.4265e-02 
 +2.5728e-02  +6.4743e-02  +5.8226e-02 
 -5.1374e-02  -1.4389e-01  -2.9953e-02 
 +4.1124e-02  -3.9211e-02  -5.0088e-02 

 Ide =  A * Pinv                   (The right inverse of A)
  +1.00   -0.00   -0.00 
  -0.00   +1.00   +0.00 
  +0.00   +0.00   +1.00 

 Press return to continue.