Linear Algebra and the C Language/a0a0


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00b.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define   RA R3
#define   CA C3
#define   Cb C5
/* ------------------------------------ */
int main(void)
{
double at[RA*CA]={
     +10,     -150,     -148, 
    +207,     -215,     +997, 
    -858,     +803,     +289  
};

double bt[RA*Cb]={
    +437,     -146,     -175,     -954,     -432, 
    -233,     +243,     +772,     +920,      -98, 
    +444,     -886,     -604,      -15,     +946  
};

double **A    =  ca_A_mR(at,     i_mR(RA,CA));
double **B    =  ca_A_mR(bt,     i_mR(RA,Cb));

double **InvA = invgj_mR(A,      i_mR(RA,CA));
double **X    =   mul_mR(InvA,B, i_mR(RA,Cb)) ;
double **T    =   mul_mR(A,X,    i_mR(RA,Cb)) ;

  clrscrn();
  printf("                                                 \n");
  printf(" Linear systems with common coefficient matrix.\n\n");
  printf("                Ax1=b1                           \n");
  printf("                Ax2=b2                           \n");
  printf("                ...                              \n");
  printf("                Axn=bn                         \n\n");
  printf(" We can write these equalities in this maner.  \n\n");
  printf("    A|x1|x2|...|xn| = b1|b2|...|bn|            \n\n");
  printf("  or simply :                                  \n\n");
  printf("              AX = B                           \n\n");
  printf("  where B = b1|b2|...|bn                       \n\n");
  printf("  and   X = x1|x2|...|xn                       \n\n");
  stop();

  clrscrn();
  printf(" We want to find X such as,   \n\n");
  printf("         AX = B               \n\n");
  printf(" If A is a square matrix and, \n\n");
  printf(" If A has an inverse matrix,  \n\n");
  printf(" you can find X by this method\n\n");
  printf("         X = inv(A) B       \n\n\n");
  printf(" To verify the result you can \n\n");
  printf(" multiply the matrix A by X.  \n\n");
  printf(" You must refind B.           \n\n");
  stop();

  clrscrn();
  printf(" A:");
  p_mR(A,S5,P0,C6);
  printf("       b1       b2      ...      bn:");
  p_mR(B,S9,P0,C6);
  stop();

  clrscrn();
  printf(" InvA:");
  pE_mR(InvA,S1,P3,C7);
  printf(" X = InvA B:");
  printf("    x1       x2       ...        xn:");
  p_mR(X,S9,P4,C6);
  stop();

  clrscrn();
  printf("       b1       b2      ...      bn:");
  p_mR(B,S9,P0,C6);
  printf("      Ax1      Ax2      ...     Axn:");
  p_mR(T,S9,P0,C6);
  stop();

  f_mR(T);
  f_mR(X);
  f_mR(B);
  f_mR(InvA);
  f_mR(A);

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


Screen output example:

                                                                                       
 Linear systems with common coefficient matrix.

                Ax1=b1                           
                Ax2=b2                           
                ...                              
                Axn=bn                         

 We can write these equalities in this maner.  

    A|x1|x2|...|xn| = b1|b2|...|bn|            

  or simply :                                  

              AX = B                           

  where B = b1|b2|...|bn                       

  and   X = x1|x2|...|xn                       

 Press return to continue. 


 We want to find X such as,   

         AX = B               

 If A is a square matrix and, 

 If A has an inverse matrix,  

 you can find X by this method

         X = inv(A) B       


 To verify the result you can 

 multiply the matrix A by X.  

 You must refind B.  

 Press return to continue. 


 A :
  +10  -150  -148 
 +207  -215  +997 
 -858  +803  +289 

       b1       b2      ...      bn :
     +437      -146      -175      -954      -432 
     -233      +243      +772      +920       -98 
     +444      -886      -604       -15      +946 

 Press return to continue. 


 inv(A) :
-6.5676e-03 -5.7471e-04 -1.3807e-03 
-6.9674e-03 -9.4468e-04 -3.0912e-04 
-1.3892e-04 +9.1861e-04 +2.2000e-04 

 X = inv(A) * B :

    x1       x2       ...      xn
  -3.3492   +2.0425   +1.5396   +5.7575   +1.5874 
  -2.9619   +1.0616   +0.6767   +5.7825   +2.8101 
  -0.1771   +0.0486   +0.6006   +0.9744   +0.1781 

 Press return to continue. 


       b1       b2      ...      bn :
     +437      -146      -175      -954      -432 
     -233      +243      +772      +920       -98 
     +444      -886      -604       -15      +946 

      Ax1      Ax2      ...     Axn :
     +437      -146      -175      -954      -432 
     -233      +243      +772      +920       -98 
     +444      -886      -604       -15      +946 

 Press return to continue.