Linear Algebra and the C Language/a0a2


Install and compile this file in your working directory.

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

  clrscrn();
  printf("      <u,v> = ||u|| ||v|| cos(a) = u1 v1 + u2 v2 + u3 v3 \n");
  printf(" u :");
  p_mR(u,S3,P0,C6);
  printf(" v :");
  p_mR(v,S3,P0,C6);
  
  printf(" <u,v> = v^t u \t      <v,u> = u^t v\n");
  printf(" <u,v> = %+.0f  \t      <v,u> = %+.0f\n\n\n", 
                dot_R(u,v), dot_R(v,u));
                
  printf(
  " if   <u,v> = 0 : u and v are orthogonal\n"
  " if   <u,v> > 0 : u and v form the shape of an acute  angle   (< )\n"
  " if   <u,v> < 0 : u and v form the shape of an obtuse angle  (\\_)\n\n"
        );
    
  f_mR(u);
  f_mR(v);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  fun(R3);

} while(stop_w());

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


Screen output example:

                                                                                       
      <u,v> = ||u|| ||v|| cos(a) = u1 v1 + u2 v2 + u3 v3 
 u :
 +6 
 -8 
 +9 

 v :
 -8 
 +3 
 -5 

 <u,v> = v^t u 	      <v,u> = u^t v
 <u,v> = -117  	      <v,u> = -117


 if   <u,v> = 0 : u and v are orthogonal
 if   <u,v> > 0 : u and v form the shape of an acute  angle   (< )
 if   <u,v> < 0 : u and v form the shape of an obtuse angle  (\_)


 Press   return to continue
 Press X return to stop