Linear Algebra and the C Language/a0g9


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00b.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r)
{
double **A       =   r_mR(         i_mR(r,r),9);
double **A_2     = pow_mR(2,A,     i_mR(r,r)); 

double **B       =   r_mR(         i_mR(r,r),9);
double **B_2     = pow_mR(2,B,     i_mR(r,r));

double **AplsB   = add_mR(A,B,     i_mR(r,r));
double **AplsB_2 = pow_mR(2,AplsB, i_mR(r,r));

double **AB      = mul_mR(A,B,     i_mR(r,r));
double **BA      = mul_mR(B,A,     i_mR(r,r));

double **T1      =                 i_mR(r,r);
double **T2      =                 i_mR(r,r);

  clrscrn();
  printf("      None commutative matrices    \n\n"
  
         "  (A+B)**2 = A**2 + AB + BA + B**2 \n\n"
         
         " A:");
  p_mR(A, S5,P3,C6);                                
  printf(" B:");
  p_mR(B, S5,P3,C6);    
  stop();
  
  clrscrn();   
  printf(" (A+B)**2:");
  p_mR(AplsB_2, S8,P3,C6);  
      
  printf(" (A+B)**2 = A**2 + AB + BA + B**2:");
  add_mR(A_2,AB,T1);
  add_mR(T1,BA,T2);
  add_mR(T2,B_2,T1);
  p_mR(T1, S8,P3,C6);
    
  f_mR(A);
  f_mR(A_2);
  
  f_mR(B);
  f_mR(B_2);
  
  f_mR(AplsB);
  f_mR(AplsB_2);
  
  f_mR(AB);
  f_mR(BA);
  
  f_mR(T1);
  f_mR(T2);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  fun(RC4);

} while(stop_w());

  return 0;
}
/*------------------------------------ */
/* ------------------------------------ */
 None commutative matrices: (A+B)**2 = A**2 + AB + BA + B**2

Screen output example:

                                                                                       
      None commutative matrices    

  (A+B)**2 = A**2 + AB + BA + B**2 

 A:
+9.000 +3.000 +6.000 -5.000 
+4.000 -6.000 -7.000 +2.000 
+7.000 +8.000 -6.000 +7.000 
+9.000 -2.000 +6.000 -7.000 

 B:
-7.000 +3.000 +6.000 -1.000 
+5.000 +9.000 -7.000 -5.000 
+9.000 -3.000 +9.000 +9.000 
+7.000 +6.000 +9.000 -1.000 

 Press return to continue. 


 (A+B)**2:
+154.000  +66.000 -114.000 +210.000 
-227.000  -19.000  -21.000 -263.000 
+381.000 +190.000 +371.000 -191.000 
+180.000 +151.000  +61.000 +196.000 

 (A+B)**2 = A**2 + AB + BA + B**2:
+154.000  +66.000 -114.000 +210.000 
-227.000  -19.000  -21.000 -263.000 
+381.000 +190.000 +371.000 -191.000 
+180.000 +151.000  +61.000 +196.000 


 Press   return to continue
 Press X return to stop