Linear Algebra and the C Language/a035


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00a.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r,int c)
{
double **A     = r_mR(i_mR(r,c),9);
double **B     = r_mR(i_mR(r,c),9);
double **AplsB =      i_mR(r,c);

  clrscrn();
  printf(" A : ");
  p_mR(A,S4,P0,C6);

  printf(" B : ");
  p_mR(B,S4,P0,C6);

  printf(" A + B : ");
  p_mR(add_mR(A,B,AplsB),S4,P0,C6);
  stop();

  clrscrn();
  printf(" Copy/Paste into the octave window.\n\n");  
  p_Octave_mR(A,"A", P0);
  p_Octave_mR(B,"B", P0);
  printf("A + B\n");
  
  p_mR(AplsB,S4,P0,C6);  

  f_mR(A);
  f_mR(B);
  f_mR(AplsB);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
  
   do 
        fun(rp_I(R4),rp_I(C4)+C2);
        
    while(stop_w());
        
  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */


Screen output example:

 A : 
  +7   +1   +2 
  -7   -2   +4 
  +6   -7   +8 
  -3   +4   +2 

 B : 
  -6   +3   +9 
  +3   -6   -3 
  +4   -5   +7 
  +5   +2   -8 

 A + B : 
  +1   +4  +11 
  -4   -8   +1 
 +10  -12  +15 
  +2   +6   -6 

 Press return to continue. 


 Copy/Paste into the octave window.

 A=[
+7,+1,+2;
-7,-2,+4;
+6,-7,+8;
-3,+4,+2]

 B=[
-6,+3,+9;
+3,-6,-3;
+4,-5,+7;
+5,+2,-8]

A + B

  +1   +4  +11 
  -4   -8   +1 
 +10  -12  +15 
  +2   +6   -6 


 Press   return to continue
 Press X return to stop