Linear Algebra and the C Language/a0mv


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :  c03c.c                   */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RA R3
#define   CA C3

#define   RX R3
#define   CX C1
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double a[RA*CA]={
    +3, -4, -2,  
    +5, -3, -1,
    +4, -3, -1   
};

double x_B[RX*CX]={
   +1,
   +2, 
   +3 
};

double b[RA*CA]={
    +1, +2, +6,   
    +3, +4, +1,
    +5, +5, +2 
};

double **A     = ca_A_mR(a,       i_mR(RA,CA));
double **B     = ca_A_mR(b,       i_mR(RA,CA));
double **x_b   = ca_A_mR(x_B,     i_mR(RX,CX));
double **invB  =  inv_mR(B,       i_mR(RA,CA));
double **invBA =  mul_mR(invB,A,  i_mR(RA,CA));
double **D     =  mul_mR(invBA,B, i_mR(RA,CA));
double **Dx_b  =  mul_mR(D,x_b,   i_mR(RA,CX));
  
  clrscrn();
  printf(" In the \"B\" basis\n\n"
         " Calculate the linear application [T(x_b)]_b = D x_b \n\n"
         " With D:     (InvB A B)");
  p_mR(D,S7,P2,C7); 
  
  printf(" And x_b:");
  p_mR(x_b,S7,P2,C7);
  
  printf(" [T(x_b)]_b = D x_b");
  p_mR(mul_mR(D,x_b,Dx_b),S8,P2,C7);
  stop();   

  f_mR(A);
  f_mR(x_b);
  
  f_mR(B);
  f_mR(invB);  
  f_mR(invBA);  
  f_mR(D);
  f_mR(Dx_b);
    
  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */

Screen output example:

                                                                                       
 In the "B" basis

 Calculate the linear application [T(x_b)]_b = D x_b 

 With D:     (InvB A B)
  +2.45   +1.52   -9.03 
  -3.48   -2.17  +13.34 
  -2.41   -2.86   -1.28 

 And x_b:
  +1.00 
  +2.00 
  +3.00 

 [T(x_b)]_b = D x_b
  -21.62 
  +32.21 
  -11.97 

 Press return to continue.