Linear Algebra and the C Language/a054


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as : addr.c                    */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
int main(void)
{
double a[R3*C3] ={  1,   2,   3,
                    2,   2,   2,
                    3,   3,   3 };
                     
double **A = ca_A_mR(a, i_mR(R3,C3));

double s;

int r1;
int r2;

 clrscrn();
 
 printf(" A :");
 p_mR(A,S5,P0,C6);
 
 s = -2.;  
 
 r1 = R1;  
 r2 = R2;
 
 printf(" Multiply R%d by %+.0f,     \n",r1,s);
 printf(" then add %+.0fR%d and R%d  \n",s,r1,r2);
 printf(" put the result into R%d  \n\n",r2);
 
 printf(" A :");
 p_mR(addR_mR(A,s,r1,r2),S5,P0,C6);
 stop();

 clrscrn();
 
 printf(" A :");
 p_mR(A,S5,P0,C6);
 
 s = -3.;  
 
 r1 = R1;  
 r2 = R3;
 
 printf(" Multiply R%d by %+.0f,     \n",r1,s);
 printf(" then add %+.0fR%d and R%d  \n",s,r1,r2);
 printf(" put the result into R%d  \n\n",r2);
 
 printf(" A :");
 p_mR(addR_mR(A,s,r1,r2),S5,P0,C6);
 stop();
 
 f_mR(A);
 
 return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Multiplies r1 by s add sr1 at r2:

Screen output example:

 A :
   +1    +2    +3 
   +2    +2    +2 
   +3    +3    +3 

 Multiply R1 by -2,     
 then add -2R1 and R2  
 put the result into R2  

 A :
   +1    +2    +3 
   +0    -2    -4 
   +3    +3    +3 

 Press return to continue. 


 A :
   +1    +2    +3 
   +0    -2    -4 
   +3    +3    +3 

 Multiply R1 by -3,     
 then add -3R1 and R3  
 put the result into R3  

 A :
   +1    +2    +3 
   +0    -2    -4 
   +0    -3    -6 

 Press return to continue.