Linear Algebra and the C Language/a0h2


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00b.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
double **X_Diag_sinh_mR(
double **A,
double **sinA)
{
int r;
int c;

  m0_mR(sinA);
  
  for     (r=R1; r<A[R_SIZE][C0]; r++)
 	  for (c=C1; c<A[C_SIZE][C0]; c++)

             if(r==c) sinA[r][c] = 10./sinh(A[r][c]);

 return(sinA);
}
/* ------------------------------------ */
/* ------------------------------------ */
double **X_Diag_cosh_mR(
double **A,
double **cosA)
{
int r;
int c;

  m0_mR(cosA);
  
  for     (r=R1; r<A[R_SIZE][C0]; r++)
 	  for (c=C1; c<A[C_SIZE][C0]; c++)

             if(r==c) cosA[r][c]=10./cosh(A[r][c]);
             
 return(cosA);
}
/* ------------------------------------ */
/* ------------------------------------ */
void X_r_commute3_mR(
double **A,
double **B,
double **C,
int      n
)
{
double **P; 
double **Pinv; 
double **D;
double **T;
double **Dt;

int r=rsize_R(A);

 P    = i_mR(r,r);
 Pinv = i_mR(r,r);
 D    = i_mR(r,r);
 T    = i_mR(r,r);
 Dt   = i_mR(r,r);
 
 while(!det_R(r_mR(P,n)));
 rdiag_mR(D,n);
 
 inv_mR(P,Pinv);
 mul_mR(P,Diag_sin_mR(D,Dt),T);
 mul_mR(T,Pinv,A);

 mul_mR(P,Diag_cos_mR(D,Dt),T);
 mul_mR(T,Pinv,B);
 
 mul_mR(P,Diag_sinh_mR(D,Dt),T);
 mul_mR(T,Pinv,C);
 
 f_mR(P);
 f_mR(Pinv);
 f_mR(D);
 f_mR(T);
 f_mR(Dt);
}
/* ------------------------------------ */
/* ------------------------------------ */
void AplsB(int r)
{
double **A  = i_mR(r,r);
double **B  = i_mR(r,r);
double **C  = i_mR(r,r);
double **T  = i_mR(r,r);

  r_commute3_mR(A,B,C,9);

  clrscrn();
  printf(" A:");
  p_mR(A, S5,P3,C6);                                
  printf(" B:");
  p_mR(B, S5,P3,C6);
  printf(" C:");
  p_mR(C, S5,P3,C6);       
  stop();

  clrscrn();
  printf(" AB:");
  p_mR(mul_mR(A,B,T), S5,P9,C6);
  printf(" BA:");
  p_mR(mul_mR(B,A,T), S5,P9,C6);
  stop();

  clrscrn();
  printf(" AC:");
  p_mR(mul_mR(A,C,T), S5,P9,C6);
  printf(" CA:");
  p_mR(mul_mR(C,A,T), S5,P9,C6);
  stop();

  clrscrn();
  printf(" BC:");
  p_mR(mul_mR(B,C,T), S5,P9,C6);
  printf(" CB:");
  p_mR(mul_mR(C,B,T), S5,P9,C6);   
  
  f_mR(A);
  f_mR(B);
  f_mR(C);
  f_mR(T);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  AplsB(RC3);

} while(stop_w());

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


Screen output example:

                                                                                       
 A:
+0.124 +0.538 -0.183 
+0.114 -0.152 +0.123 
+0.076 -0.447 +0.307 

 B:
+0.455 +2.248 -0.428 
+0.206 -0.669 -0.061 
-0.619 -0.964 -0.806 

 C:
-0.624 +1.470 -0.850 
+0.594 -1.406 +0.933 
+1.178 -2.160 +1.980 

 Press return to continue. 


 AB:
+0.281028640 +0.095647831 +0.061614365 
-0.055417848 +0.239779207 -0.138810729 
-0.247938842 +0.173148354 -0.252521387 

 BA:
+0.281028640 +0.095647831 +0.061614365 
-0.055417848 +0.239779207 -0.138810729 
-0.247938842 +0.173148354 -0.252521387 

 Press return to continue. 


 AC:
+0.026193141 -0.178383437 +0.033977797 
-0.016382152 +0.115384859 +0.004853971 
+0.049146457 +0.076450044 +0.126306294 

 CA:
+0.026193141 -0.178383437 +0.033977797 
-0.016382152 +0.115384859 +0.004853971 
+0.049146457 +0.076450044 +0.126306294 

 Press return to continue. 

 ...