Linear Algebra and the C Language/a0le


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as:   c00e1.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RC RC3
/* ------------------------------------ */
/* ------------------------------------ */
void fun()
{
double **Q  = r_Q_mR(     i_mR(RC,RC),9);
double **u  =   r_mR(     i_mR(RC,C1),9);
double **v  =   r_mR(     i_mR(RC,C1),9);

double **Qu = mul_mR(Q,u, i_mR(RC,C1));
double **Qv = mul_mR(Q,v, i_mR(RC,C1));
  
  clrscrn();   
  printf(" Q:                an orthonormal matrix ");
  p_mR(Q, S3,P4,C6);
  
  printf(" u:");
  p_mR(u, S3,P1,C6);

  printf(" v:");
  p_mR(v, S3,P1,C6);
  
  printf(" Orthonormal matrices preserve the dot product\n\n"
         "  Q u . Q v\t   =   u . v                     \n\n"          
         "    %.4f\t   =   %.4f                         \n\n",
          dot_R(Qu, Qv),    dot_R(u,v));
   
  f_mR(u);
  f_mR(v); 
  f_mR(Qu);
  f_mR(Qv);
  f_mR(Q);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
do
{
  fun();

} while(stop_w());

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

Screen output example:

                                                                                       
 Q:                an orthonormal matrix 
+0.1961 -0.7319 -0.6526 
-0.7845 +0.2822 -0.5522 
-0.5883 -0.6203 +0.5188 

 u:
-8.0 
+6.0 
+5.0 

 v:
-6.0 
+8.0 
-4.0 

 Orthonormal matrices preserve the dot product

  Q u . Q v	   =   u . v                     

    76.0000	   =   76.0000                         


 Press   return to continue
 Press X return to stop