Linear Algebra and the C Language/a04j


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00c.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA   R5
#define CA   C4 
#define Cb   C1 
/* ------------------------------------ */
#define FACTOR_E        +1.E-0         
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA+Cb)]={
// x2    x4    x6    x7
   -1,   +0,   +0,   +0,
   +1,   +1,   +0,   +0,
   +0,   +0,   +1,   -1,
   +0,   +0,   +0,   +1,
   +0,   -1,   -1,   +0, 
};

double tb[RA*(CA+Cb)]={
     +20 -50,
         +60,  
         -60,
     +90 -20,
     +50 -90 
};

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);
  stop(); 

  clrscrn();   
  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  +1.0  +0.0  +0.0 
 +0.0  +0.0  +1.0  -1.0 
 +0.0  +0.0  +0.0  +1.0 
 +0.0  -1.0  -1.0  +0.0 

 b :
-30.0 
+60.0 
-60.0 
+70.0 
-40.0 

 Press return to continue. 


 Pinv = V * invS_T * U_T 
 -8.0000e-01  +2.0000e-01  +2.0000e-01  +2.0000e-01  +2.0000e-01 
 +6.0000e-01  +6.0000e-01  -4.0000e-01  -4.0000e-01  -4.0000e-01 
 -4.0000e-01  -4.0000e-01  +6.0000e-01  +6.0000e-01  -4.0000e-01 
 -2.0000e-01  -2.0000e-01  -2.0000e-01  +8.0000e-01  -2.0000e-01 

 x = Pinv * b 
  +30.0000 
  +30.0000 
  +10.0000 
  +70.0000 

 Press return to continue.