Linear Algebra and the C Language/a0fb


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00a.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
double **X_c_A_b_Ab_mR(
double **A,
double **b,
double **Ab
)
{
int r;
int c;
int c_A;

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

            Ab[r][c] = A[r][c];

             c_A = --c;

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

            Ab[r][c+c_A] = b[r][c];
            
return(Ab);
}
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r)
{
double **A  = r_mR(i_mR(r,r ),999);
double **b  = r_mR(i_mR(r,C1),999);
double **Ab = i_Abr_Ac_bc_mR(r,    r,   C1);
/*            i_Abr_Ac_bc_mR(R_Ab, C_A, C_b));  */

  clrscrn();
  printf(" A :");
  p_mR(A, S5,P0,C12);
  
  printf(" b :");
  p_mR(b, S5,P0,C12);

  printf(" Ab :  c_A_b_Ab_mR(A,b, Ab)");
  p_mR(c_A_b_Ab_mR(A,b, Ab), S5,P0,C12);

  f_mR(Ab);
  f_mR(b);
  f_mR(A);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
do
{
  fun(rp_I(RC3)+R1); /* +R1 -> row >= R2 */


} while(stop_w());

  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Copy A and b into Ab:Gauss-Jordan

Screen output example:

                                                                                       
 A :
 +357  +871  -673  +453 
 -156   +91  -344  -147 
 +878  +274  -522  -907 
 -665  +967  +145  -934 

 b :
 -668 
 +691 
 +642 
 -111 

 Ab :  c_A_b_Ab_mR(A,b, Ab)
 +357  +871  -673  +453  -668 
 -156   +91  -344  -147  +691 
 +878  +274  -522  -907  +642 
 -665  +967  +145  -934  -111 


 Press   return to continue
 Press X return to stop