Linear Algebra and the C Language/a0in


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00b.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
int main(void)
{
double a[R2*C3]={ 1,2,3,
                  4,5,6};
                  
double b[R3*C2]={ 6,5,
                  3,2,
                  4,5};
                  
/* ----------- Copy "a" into A -------- */
double **A  = ca_A_mR(a, i_mR(R2,C3));
/* ------------------------------------ */

/* ----------- Copy "b" into B -------- */
double **B  = ca_A_mR(b, i_mR(R3,C2));
/* ------------------------------------ */

double **AB =  mul_mR(A,B,i_mR(R2,C2));

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

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

  printf(" AB:");
  p_mR(AB, 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\n\n\n");

  printf(" AB:");  
  p_mR(AB, S4,P0,C6);  
  stop();
  
  f_mR(A);
  f_mR(B);
  f_mR(AB);

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

Screen output example:

                                                                                       
 A:
  +1   +2   +3 
  +4   +5   +6 

 B:
  +6   +5 
  +3   +2 
  +4   +5 

 AB:
 +24  +24 
 +63  +60 

 Press return to continue. 


 Copy/Paste into the octave window.

 A=[
+1,+2,+3;
+4,+5,+6]

 B=[
+6,+5;
+3,+2;
+4,+5]

A * B



 AB:
 +24  +24 
 +63  +60 

 Press return to continue.