Linear Algebra and the C Language/a0l2


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as:     c00a.c                 */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
# define RAb    C4
# define CA     C6
# define Cb     C1
/* ------------------------------------ */
# define FREEV  C3
/* ------------------------------------ */
/* ------------------------------------ */
void X_put_zeroR_mR(
double **Ab,
double **Ab_free
)
{
int r;
int c;

int r_free= R1;
int t=0;

 	for    (r=R1;   r<Ab[R_SIZE][C0];   r++)
 	   for (c=r+t;  c<Ab[C_SIZE_A][C0]; c++)
 	   
        if(Ab[r][c]> ERROR_E)             /* Copy a row of Ab into    */ 
          {                               /* the row of    Ab_free    */
            c_r_mR(Ab,r, Ab_free,r_free); /* if the pivot is not zero */
            c = Ab[C_SIZE_A][C0];
            r_free++;
          }
        else                              /* if the pivot is zero     */
        {                                 /* skip a row               */
		  r_free++;
		  t++;
	    }

}
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double ab[RAb*(CA+Cb)]={
  +1.0,   -3.0,   +4.5,   -0.5,   +4.0,   +1.0,   +0.0, 
  -0.0,   -0.0,   +1.0,   +3.0,   -2.0,   -6.0,   -0.0, 
  +0.0,   +0.0,   +0.0,   +0.0,   +1.0,   +5.0,   +0.0, 
  +0.0,   +0.0,   +0.0,   +0.0,   +0.0,   +0.0,   +0.0  
};

double **Ab      =   ca_A_mR(ab, i_Abr_Ac_bc_mR(RAb, CA, Cb));
double **Ab_free =               i_Abr_Ac_bc_mR(CA,  CA, Cb + FREEV);

  clrscrn();
  printf(" Ab:                                  b");
  p_mR(Ab, S5,P1,C10);
  
  X_put_zeroR_mR(Ab,Ab_free); 

  printf(" See above for the function code: put_zeroR_mR();\n\n" 
         " A of Ab_free must be a square matrix: A[CA,CA]\n\n" 
         " Ab_free:                             b     FREEV");            
  p_mR(Ab_free, S5,P1,C10);  
  stop();

  f_mR(Ab);
  f_mR(Ab_free);

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

Screen output example:

                                                                                       
 Ab:                                  b
 +1.0  -3.0  +4.5  -0.5  +4.0  +1.0  +0.0 
 -0.0  -0.0  +1.0  +3.0  -2.0  -6.0  -0.0 
 +0.0  +0.0  +0.0  +0.0  +1.0  +5.0  +0.0 
 +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0 

 See above for the function code: put_zeroR_mR();

 A of Ab_free must be a square matrix: A[CA,CA]

 Ab_free:                             b     FREEV
 +1.0  -3.0  +4.5  -0.5  +4.0  +1.0  +0.0  +0.0  +0.0  +0.0 
 +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0 
 -0.0  -0.0  +1.0  +3.0  -2.0  -6.0  -0.0  +0.0  +0.0  +0.0 
 +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0 
 +0.0  +0.0  +0.0  +0.0  +1.0  +5.0  +0.0  +0.0  +0.0  +0.0 
 +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0  +0.0 

 Press return to continue.