Linear Algebra and the C Language/a031


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00b.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
int main(void)
{ 
double u_T[R1*C3] = {    4,   2,   5};                                             
double v_T[R1*C3] = {    3,   4,   1};

double **U_T = ca_A_mR(u_T ,    i_mR(R1,C3));
double **V_T = ca_A_mR(v_T ,    i_mR(R1,C3));  
double **UxV =  UxV_mR(U_T,V_T, i_mR(R1,C3));
double **A   =                  i_mR(R3,C3);

  clrscrn(); 
  printf("  u_T:");
  p_mR(U_T, S4, P0, C6);
  printf("  v_T:");
  p_mR(V_T, S4, P0, C6);

  printf("\n\n" 
         "    u x v : With UxV_mR();");    
  p_mR(UxV, S5, P0, C6); 
 
  
//     u and v -> A
  c_r_mR(U_T, R1, A, R2);
  c_r_mR(V_T, R1, A, R3);

// cofactor A:R1 -> (u x v)  
  c_s_mR(cofactor_R(A, R1, C1), UxV, R1, C1);
  c_s_mR(cofactor_R(A, R1, C2), UxV, R1, C2);
  c_s_mR(cofactor_R(A, R1, C3), UxV, R1, C3);
       
  printf("\n\n" 
         "    u x v : With cofactor_R(); ");    
  p_mR(UxV, S5, P0, C6);
  
  stop();                        
  
  f_mR(U_T); 
  f_mR(V_T);
  f_mR(UxV);       
  f_mR(A); 

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

Vectors in mathematics are assumed to be column vectors, which is why I use _T (Transpose) to display row vectors.

Screen output example:

  u_T:
  +4   +2   +5 

  v_T:
  +3   +4   +1 



    u x v : With UxV_mR();
  -18   +11   +10 



    u x v : With cofactor_R(); 
  -18   +11   +10 

 Press return to continue.