Linear Algebra and the C Language/a0lj


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as:   c03c.c                   */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define RAT R2
#define CAT C3
#define Cb  C1
/* ------------------------------------ */
#define CFREEV Cb+C1   
/* ------------------------------------ */
int main(void)
{
double a_Tb[RAT*(CAT+Cb)]={
 -2,1,0,0,
 -3,0,1,0
};

double **ATb =   ca_A_mR(a_Tb, i_Abr_Ac_bc_mR(RAT,CAT,Cb));
double **AT  = c_Ab_A_mR(ATb,            i_mR(RAT,CAT));
double **b   = c_Ab_b_mR(ATb,            i_mR(RAT,Cb));

double **ATb_free =            i_Abr_Ac_bc_mR(CAT,CAT,CFREEV);

double **B   =                           i_mR(CAT,CFREEV); 
double **ATB =                           i_mR(RAT,CFREEV); 

  clrscrn();
  printf("Find a basis B for the orthogonal complement of AT.\n\n" 
         " AT:");
  p_mR(AT,S6,P1,C10);
  
  printf(" b:");
  p_mR(b,S6,P1,C10);
  
  printf(" ATb:");
  p_mR(ATb,S6,P1,C10);
  stop();

  clrscrn();
  printf(" ATb:  gj_PP_mR(ATb,NO);");
  p_mR(gj_PP_mR(ATb,NO),S7,P3,C10);
  
  put_zeroR_mR(ATb,ATb_free);  
  put_freeV_mR(ATb_free);
   
  printf(" ATb_free:                b       CFREEV");  
  p_mR(gj_PP_mR(ATb_free,YES),S7,P3,C10);  
  
  printf(" The free variables of the system above\n"
         " are a basis for the orthogonal complement of AT.\n\n"
         " B:               Copy the coefficients in the next C file."); 
  P_mR(c_Ab_b_mR(ATb_free,B),S10,P12,C7);
  stop();	
  
  clrscrn();
  printf("Verify if B is a basis for"
         " the orthogonal complement of AT\n\n"
         " AT:"  );
  p_mR(AT, S7,P3,C10); 
  
  printf(" B:"); 
  p_mR(B, S7,P3,C10); 
  
  printf(" AT B:             AT and B are orthogonal"); 
  p_mR(mul_mR(AT,B,ATB), S7,P6,C10); 
  stop();  
  
  f_mR(ATb);
  f_mR(AT);
  f_mR(b);
  
  f_mR(ATb_free);
  
  f_mR(B);
  f_mR(ATB);
    
  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */

Screen output example:

                                                                                       
Find a basis for the orthogonal complement of AT.

 AT:
  -2.0   +1.0   +0.0 
  -3.0   +0.0   +1.0 

 b:
  +0.0 
  +0.0 

 ATb:
  -2.0   +1.0   +0.0   +0.0 
  -3.0   +0.0   +1.0   +0.0 

 Press return to continue. 


 ATb:  gj_PP_mR(ATb,NO);
 +1.000  -0.000  -0.333  -0.000 
 +0.000  +1.000  -0.667  +0.000 

 ATb_free:                b       CFREEV
 +1.000  +0.000  +0.000  +0.000  +0.333 
 +0.000  +1.000  +0.000  +0.000  +0.667 
 +0.000  +0.000  +1.000  +0.000  +1.000 

 The free variables of the system above
 are a basis for the orthogonal complement of AT.

 B:               Copy the coefficients in the next C file.
+0.000000000000, +0.333333333333, 
+0.000000000000, +0.666666666667, 
+0.000000000000, +1.000000000000  

 Press return to continue. 


Verify if B is a basis for the orthogonal complement of AT

 AT:
 -2.000  +1.000  +0.000 
 -3.000  +0.000  +1.000 

 B:
 +0.000  +0.333 
 +0.000  +0.667 
 +0.000  +1.000 

 AT B:             AT and B are orthogonal
+0.000000 +0.000000 
+0.000000 +0.000000 

 Press return to continue.