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  = i_mR(r,r);
double **b  = i_mR(r,r);
double **Ab = i_Abr_Ac_bc_mR(r,   r,  r);
/*            i_Abr_Ac_bc_mR(R_Ab,C_A,C_b)); */

double **invA = i_mR(r,r);

 do
  {
   r_mR(A,999.);
   printf(".");
  }while(!det_R(A));

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

  printf("   b : ID :");
  eye_mR(b);
  p_mR(b,S8,P0,C4);
  stop();
  
  clrscrn();  
  printf(" Ab :");
  c_A_b_Ab_mR(A,b,Ab);
  p_mR(Ab,S8,P0,C4);
  printf("  gj_TP_mR(Ab) :");  
  gj_TP_mR(Ab);
  pE_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 :
     -28     +696     +826     +438 
    -491     -110     -827     +935 
    -548     +535     +619     +446 
    -505     +150     -363     +935 

   b : ID :
      +1       +0       +0       +0 
      +0       +1       +0       +0 
      +0       +0       +1       +0 
      +0       +0       +0       +1 

 Press return to continue. 


 Ab :
     -28     +696     +826     +438 
    -491     -110     -827     +935 
    -548     +535     +619     +446 
    -505     +150     -363     +935 

      +1       +0       +0       +0 
      +0       +1       +0       +0 
      +0       +0       +1       +0 
      +0       +0       +0       +1 

  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.2174e-04    -3.0821e-03    -2.8386e-03    +4.0512e-03 
   +1.1892e-02    +4.2633e-02    +1.0019e-02    -5.2983e-02 
   -6.6387e-03    -2.6137e-02    -5.7000e-03    +3.1966e-02 
   -4.0413e-03    -1.8652e-02    -5.3535e-03    +2.4168e-02 

 Press return to continue. 


 Copy/Paste into the octave window.

 A=[
-28,+696,+826,+438;
-491,-110,-827,+935;
-548,+535,+619,+446;
-505,+150,-363,+935]

format short e
 inv(A)

 invA :                      c_Inv_A_mR(Ab,invA);
   +8.2174e-04    -3.0821e-03    -2.8386e-03    +4.0512e-03 
   +1.1892e-02    +4.2633e-02    +1.0019e-02    -5.2983e-02 
   -6.6387e-03    -2.6137e-02    -5.7000e-03    +3.1966e-02 
   -4.0413e-03    -1.8652e-02    -5.3535e-03    +2.4168e-02 


 Press   return to continue
 Press X return to stop