Linear Algebra and the C Language/a030


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00a.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(void)
{ 
double **U_T =   r_mR(         i_mR(R1,C3), 9);  
double **V_T =   r_mR(         i_mR(R1,C3), 9);   
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);
        
  f_mR(U_T); 
  f_mR(V_T);
  f_mR(UxV); 
  f_mR(A); 
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
  
do
{  
  fun();

} while(stop_w());

  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:
  +5   +8   -3 

  v_T:
  +6   -4   -7 



    u x v : With UxV_mR();
  -68   +17   -68 



    u x v : With cofactor_R(); 
  -68   +17   -68 


 Press   return to continue
 Press X return to stop