Linear Algebra and the C Language/a0mh


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :  c00b.c                   */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r,int c)
{
double **A    =         r_mR(       i_mR(r,c),9);
double **A_t  = transpose_mR(A,     i_mR(c,r));
double **AA_t =       mul_mR(A,A_t, i_mR(r,r));
double **A_tA =       mul_mR(A_t,A, i_mR(c,c));

  clrscrn();
  printf(" A:\n");
  p_mR(A,3,0,C6);
  printf(" A_t:  (transpose)\n");
  p_mR(A_t,S3,P0,C6);
  stop();

  clrscrn();
  printf(" Let's multiply a matrix by its transpose. \n"
         " We get a square matrix, with values ​​always\n"
         " positive on the diagonal.\n\n"
         " AA_t: ");
  p_mR(AA_t,S8,P0,C6);
  printf(" A_tA: ");
  p_mR(A_tA,S8,P0,C6);  
  
  f_mR(A);
  f_mR(A_t);
  f_mR(AA_t);
  f_mR(A_tA);  
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
  
  do 
    fun(rp_I(R6),rp_I(C6));
        
  while(stop_w());

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

Screen output example:

                                                                                       
 A:

 +7  +2  +7  -5 
 +7  +4  +6  +7 

 A_t:  (transpose)

 +7  +7 
 +2  +4 
 +7  +6 
 -5  +7 

 Press return to continue. 


 Let's multiply a matrix by its transpose. 
 We get a square matrix, with values ​​always
 positive on the diagonal.

 AA_t: 
    +127      +64 
     +64     +150 

 A_tA: 
     +98      +42      +91      +14 
     +42      +20      +38      +18 
     +91      +38      +85       +7 
     +14      +18       +7      +74 


 Press   return to continue
 Press X return to stop