Linear Algebra and the C Language/a09f


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00c.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
double **xx_GJ_TPfreeV_mR(
double **Ab,
double **new_Ab)
{
int r;
	            
  c_mR(Ab,new_Ab);
  
  clrscrn();
  printf(" ---------------DEBUG 1 ------------ \n");
  printf(" new_Ab : put the zero rows");
  p_mR(new_Ab,S8,P4,C8); 
                                                           
  put_freeV_TP_mR(new_Ab,Ab[R_SIZE][C0]);
  
  printf(" new_Ab : put_freeV_TP_mR()");
  p_mR(new_Ab,S8,P4,C8); 
  stop(); 
  
  clrscrn();  
  printf(" ---------------DEBUG 2 ------------ \n"); 
  printf(" Copy/Paste into the octave window.\n\n");
  p_Octave_mR(new_Ab,"new_Ab",P8);
  printf("\n rref(new_Ab,.00000000001)\n\n");
  stop();
    
  clrscrn();  
  printf(" -- VERIFY THE RESULT INTO OCTAVE --\n"); 

  r = rsize_R(new_Ab);
  
  while(r>R1)
    
        zero_above_pivot_gj1Ab_mR(new_Ab,r--);	
	
return(new_Ab);
}
/* ------------------------------------ */
/* ------------------------------------ */

void fun(int r, int c)
{
double **A  = i_mR(r,c);
double **b  = i_mR(r,C1);
double **Ab = i_Abr_Ac_bc_mR(r,c,C1);

double **new_Ab = i_Abr_Ac_bc_mR(csize_A_R(Ab), 
                                 csize_A_R(Ab),
                                 csize_R(A)-rsize_R(A) + C1);  

  r_mR(A,999.);
  r_mR(b,999.);
  
  clrscrn();
  printf(" A :");
  p_mR(A,S8,P0,C7);
  
  printf(" b :");
  p_mR(b,S8,P0,C7);
  
  printf(" Ab :");
  c_A_b_Ab_mR(A,b,Ab);
  p_mR(Ab,S8,P0,C7);
  stop();

  clrscrn();
  GJ_TP_mR(Ab);
  printf(" Ab :");
  p_mR(Ab,S10,P4,C7);
  stop();  
  
  clrscrn();
  xx_GJ_TPfreeV_mR(Ab,new_Ab); 
  printf(" new_Ab :"); 
  p_mR(new_Ab,S10,P4,C7);
  
  f_mR(new_Ab);  
  f_mR(Ab);
  f_mR(b);
  f_mR(A);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
do
{
    fun(R3, C5);

} while(stop_w());

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


  • The algorithm consists to copy Ab into new_Ab.
  • Put the free variables.
  • Solve the system.


Screen output example:

 A :
    +527     +338     +215     -610     +716 
    -599     +299     +222     +936     +969 
    -515      -54     +286     +484     -862 

 b :
    -413 
    +365 
    +535 

 Ab :
    +527     +338     +215     -610     +716     -413 
    -599     +299     +222     +936     +969     +365 
    -515      -54     +286     +484     -862     +535 

 Press return to continue. 


 Ab :
   +1.0000    +0.0000    +0.0000    -1.4057    -0.4009    -0.6688 
   +0.0000    +1.0000    +0.0000    +0.8220    +4.5707    -0.5383 
   +0.0000    +0.0000    +1.0000    -0.6838    -2.8728    +0.5647 

 Press return to continue. 


 ---------------DEBUG 1 ------------ 
 new_Ab : put the zero rows
 +1.0000  +0.0000  +0.0000  -1.4057  -0.4009  -0.6688  +0.0000  +0.0000 
 +0.0000  +1.0000  +0.0000  +0.8220  +4.5707  -0.5383  +0.0000  +0.0000 
 +0.0000  +0.0000  +1.0000  -0.6838  -2.8728  +0.5647  +0.0000  +0.0000 
 +0.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000 
 +0.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000 

 new_Ab : put_freeV_TP_mR()
 +1.0000  +0.0000  +0.0000  -1.4057  -0.4009  -0.6688  +0.0000  +0.0000 
 +0.0000  +1.0000  +0.0000  +0.8220  +4.5707  -0.5383  +0.0000  +0.0000 
 +0.0000  +0.0000  +1.0000  -0.6838  -2.8728  +0.5647  +0.0000  +0.0000 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0000  +0.0000  +1.0000  +0.0000 
 +0.0000  +0.0000  +0.0000  +0.0000  +1.0000  +0.0000  +0.0000  +1.0000 

 Press return to continue. 


 ---------------DEBUG 2 ------------ 
 Copy/Paste into the octave window.

 new_Ab=[
+1.00000000,+0.00000000,+0.00000000,-1.40572248,-0.40085983,-0.66878463,+0.00000000,+0.00000000;
+0.00000000,+1.00000000,+0.00000000,+0.82197607,+4.57073089,-0.53834817,+0.00000000,+0.00000000;
+0.00000000,+0.00000000,+1.00000000,-0.68377751,-2.87280889,+0.56470319,+0.00000000,+0.00000000;
+0.00000000,+0.00000000,+0.00000000,+1.00000000,+0.00000000,+0.00000000,+1.00000000,+0.00000000;
+0.00000000,+0.00000000,+0.00000000,+0.00000000,+1.00000000,+0.00000000,+0.00000000,+1.00000000]


 rref(new_Ab,.00000000001)

 Press return to continue. 


 -- VERIFY THE RESULT INTO OCTAVE --
 new_Ab :
   +1.0000    +0.0000    +0.0000    +0.0000    +0.0000    -0.6688    +1.4057 
   +0.0000    +1.0000    +0.0000    +0.0000    +0.0000    -0.5383    -0.8220 
   +0.0000    +0.0000    +1.0000    +0.0000    +0.0000    +0.5647    +0.6838 
   +0.0000    +0.0000    +0.0000    +1.0000    +0.0000    +0.0000    +1.0000 
   +0.0000    +0.0000    +0.0000    +0.0000    +1.0000    +0.0000    +0.0000 

   +0.4009 
   -4.5707 
   +2.8728 
   +0.0000 
   +1.0000 


 Press   return to continue
 Press X return to stop