Linear Algebra and the C Language/a03l


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as:   c01a.c                   */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define   RA R5
#define   CA C3
/* ------------------------------------ */
#define FACTOR_E        +1.E-0         
/* ------------------------------------ */
void fun(void)
{
double **A    =       r_mR(        i_mR(RA,CA),9);
double **Pinv = Pinv_Rn_mR(A,      i_mR(CA,RA),FACTOR_E);; 
double **Ide  =     mul_mR(Pinv,A, i_mR(CA,CA));  ;         

  clrscrn();
  printf(" A:");
  p_mR(A, S7,P2,C7);

  printf(" Pinv = V invS_T U_T ");
  pE_mR(Pinv, S12,P4,C10); 
  
  printf(" Ide = Pinv A                     (The left inverse of A)"); 
  p_mR(Ide, S7,P2,C10); 
      
  f_mR(A);
  f_mR(Pinv);
  f_mR(Ide); 
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
do
{
  fun();


} while(stop_w());

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

Screen output example:

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

 Pinv = V * invS_T * U_T 
 -4.4894e-02  +3.7031e-02  -6.0278e-02  -3.7050e-02  -7.6661e-02 
 +5.4343e-03  -1.1026e-01  -9.0613e-03  +1.2118e-02  +1.0961e-01 
 -5.0855e-02  +9.2656e-02  +3.7499e-02  +4.2000e-02  -1.8955e-02 

 Ide = Pinv * A                        (The left 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
 Press X return to stop