Linear Algebra and the C Language/a073


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as:   c00e.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r)
{
double **A    =        r_mR(               i_mR(r,r),999);
double **b    =      eye_mR(               i_mR(r,r));
double **Ab   = c_A_b_Ab_mR(A,b, i_Abr_Ac_bc_mR(r,r,r));
double **invA =                            i_mR(r,r);

  clrscrn();
  printf(" A:");
  p_mR(A, S8,P2,C4);

  printf(" b: ID");
  p_mR(b, S8,P2,C4);
  stop();
  
  clrscrn();  
  printf(" Ab:");
  p_mR(Ab, S8,P2,C4);
  
  printf("  gj_TP_mR(Ab):");  
  pE_mR(gj_TP_mR(Ab), S14,P4,C4);
  stop();
  
  clrscrn(); 
  printf(" Copy/Paste into the octave window.\n\n");
  p_Octave_mR(A,"A",P0);
  printf("format short e\n");
  printf(" inv(A)\n\n");

  printf(" invA:                      c_Inv_A_mR(Ab,invA);");
  c_Inv_A_mR(Ab,invA);  
  pE_mR(invA, S14,P4,C4);
  
  f_mR(invA);
  f_mR(Ab);
  f_mR(b);
  f_mR(A);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
do
{
  fun(R4);
} while(stop_w());

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

Screen output example:

 A:
  +27.00  +514.00  +786.00  -868.00 
 -767.00  +143.00  +389.00  -851.00 
  +35.00  -354.00  -232.00  -250.00 
 -729.00  -765.00  +492.00  +186.00 

   b: ID:
   +1.00    +0.00    +0.00    +0.00 
   +0.00    +1.00    +0.00    +0.00 
   +0.00    +0.00    +1.00    +0.00 
   +0.00    +0.00    +0.00    +1.00 

 Press return to continue. 


 Ab:
  +27.00  +514.00  +786.00  -868.00 
 -767.00  +143.00  +389.00  -851.00 
  +35.00  -354.00  -232.00  -250.00 
 -729.00  -765.00  +492.00  +186.00 

   +1.00    +0.00    +0.00    +0.00 
   +0.00    +1.00    +0.00    +0.00 
   +0.00    +0.00    +1.00    +0.00 
   +0.00    +0.00    +0.00    +1.00 

  gj_TP_mR(Ab):
   +1.0000e+00    +0.0000e+00    +0.0000e+00    +0.0000e+00 
   -0.0000e+00    +1.0000e+00    -0.0000e+00    -0.0000e+00 
   +0.0000e+00    +0.0000e+00    +1.0000e+00    +0.0000e+00 
   +0.0000e+00    +0.0000e+00    +0.0000e+00    +1.0000e+00 

   +8.8692e-04    -1.1842e-03    +9.1528e-04    -4.8994e-05 
   -2.9456e-04    +5.8773e-04    -1.4997e-03    -7.0127e-04 
   +1.0036e-03    -7.1404e-04    -4.8472e-04    +7.6516e-04 
   -3.9010e-04    -3.3539e-04    -1.2985e-03    +2.7608e-04 

 Press return to continue. 


 Copy/Paste into the octave window.

 A=[
+27,+514,+786,-868;
-767,+143,+389,-851;
+35,-354,-232,-250;
-729,-765,+492,+186]

format short e
 inv(A)

 invA:                      c_Inv_A_mR(Ab,invA);
   +8.8692e-04    -1.1842e-03    +9.1528e-04    -4.8994e-05 
   -2.9456e-04    +5.8773e-04    -1.4997e-03    -7.0127e-04 
   +1.0036e-03    -7.1404e-04    -4.8472e-04    +7.6516e-04 
   -3.9010e-04    -3.3539e-04    -1.2985e-03    +2.7608e-04 


 Press   return to continue
 Press X return to stop