Linear Algebra and the C Language/a0gb


Install and compile this file in your working directory.

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

double **B       = i_mR(r,r);
double **B_2     = i_mR(r,r);

double **AplsB   = i_mR(r,r);
double **AplsB_2 = i_mR(r,r);

double **AB      = i_mR(r,r);
double **AB2     = i_mR(r,r);

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

  r_commute2_mR(A,B,9);

  clrscrn();
  printf("      Commutative matrices     \n\n"

         "  (A+B)**2 = A**2 + 2*AB + 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:");
  add_mR(A,B,AplsB);
  pow_mR(2,AplsB,AplsB_2);
  p_mR(AplsB_2, S8,P3,C6);  
      
  printf(" (A+B)**2 = A**2 + 2*AB + B**2:");
  pow_mR(2,A,A_2); 
   
  mul_mR(A,B,AB);
 smul_mR(2,AB,AB2);
 
  pow_mR(2,B,B_2);
  
  add_mR(A_2,AB2,T1);
  add_mR(T1,B_2,T2);
  
  p_mR(T2, 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(AB2);
  
  f_mR(T1);
  f_mR(T2);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  fun(RC4);

} while(stop_w());

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

Screen output example:

                                                                                       
      Commutative matrices

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

 A:
+0.372 +0.133 +0.110 +0.115 
+0.190 +0.547 -0.067 +0.303 
-0.266 +0.100 +0.967 +0.020 
-0.033 +0.276 +0.031 +0.624 

 B:
-0.623 -0.123 +0.026 +0.235 
-1.450 +0.501 +0.347 -0.298 
+0.063 -0.156 -0.442 +0.140 
+1.279 -0.748 -0.301 -0.220 

 Press return to continue. 


 (A+B)**2:
  +0.460   -0.166   -0.054   +0.076 
  -1.054   +1.068   +0.267   -0.389 
  +0.214   -0.165   +0.189   +0.077 
  +0.842   -0.660   -0.213   +0.555 

 (A+B)**2 = A**2 + 2*AB + B**2:
  +0.460   -0.166   -0.054   +0.076 
  -1.054   +1.068   +0.267   -0.389 
  +0.214   -0.165   +0.189   +0.077 
  +0.842   -0.660   -0.213   +0.555 


 Press   return to continue
 Press X return to stop