Linear Algebra and the C Language/a037


Install and compile this file in your working directory.

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

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

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

  printf(" AB : ");
  p_mR(mul_mR(A,B,AB),S8,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(AB,S4,P0,C6);  

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

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


Screen output example:

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

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

 AB : 
     +84      -16      -27      +75 
     -33      -83      +84      +33 
     -32      +70      -50      -54 
     +53      -20      -10      +57 

 Press return to continue. 


 Copy/Paste into the octave window.

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

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

A * B

 +84  -16  -27  +75 
 -33  -83  +84  +33 
 -32  +70  -50  -54 
 +53  -20  -10  +57 


 Press   return to continue
 Press X return to stop