Linear Algebra and the C Language/a04h


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00b.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA   R4
#define CA   C3 
#define Cb   C1 
/* ------------------------------------ */
#define FACTOR_E        +1.E-0         
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA+Cb)]={
//  x1   x3   x4       
    +1,  +0,  +0, // A
    +0,  +1,  +0, // B   
    +0,  -1,  +1, // C
    -1,  +0,  -1  // D  
};

double tb[RA*(CA+Cb)]={
        +20+10, // A
   +60 -10 -30, // B   
           +20, // C
       -100+30, // D  
};

double **A       = ca_A_mR(ta,i_mR(RA,CA));    
double **b       = ca_A_mR(tb,i_mR(RA,C1));
double **Pinv    =            i_mR(CA,RA);           
double **x       =            i_mR(CA,C1);          

  clrscrn();
  printf(" A :");
  p_mR(A,S5,P1,C6);
  printf(" b :");
  p_mR(b,S5,P1,C6);
   
  printf(" Pinv = V * invS_T * U_T ");
  Pinv_Rn_mR(A,Pinv,FACTOR_E); 
  pE_mR(Pinv,S12,P4,C6);   
  
  printf(" x = Pinv * b ");   
  mul_mR(Pinv,b,x); 
  p_mR(x,S10,P4,C6);  
  stop();  
  
  f_mR(b);   
  f_mR(A);
  f_mR(Pinv);
  f_mR(x); 

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

Screen output example:

 A :
 +1.0  +0.0  +0.0 
 +0.0  +1.0  +0.0 
 +0.0  -1.0  +1.0 
 -1.0  +0.0  -1.0 

 b :
+30.0 
+20.0 
+20.0 
-70.0 

 Pinv = V * invS_T * U_T 
 +7.5000e-01  -2.5000e-01  -2.5000e-01  -2.5000e-01 
 -2.5000e-01  +7.5000e-01  -2.5000e-01  -2.5000e-01 
 -5.0000e-01  +5.0000e-01  +5.0000e-01  -5.0000e-01 

 x = Pinv * b 
  +30.0000 
  +20.0000 
  +40.0000 

 Press return to continue.