Linear Algebra and the C Language/a0cq


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :  c00b.c                   */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define   RCA R2
/* ------------------------------------ */
int main(void)
{
double a[RCA*RCA]={
+1,+2,
+2,+1};

double      R = 3;
double Ev1Ev2 = 0;

double **A        =      ca_A_mR(a,       i_mR(RCA,RCA));
double **EVector  =    eigs_V_mR(A,       i_mR(RCA,RCA)); 
double **EVectorT = transpose_mR(EVector, i_mR(RCA,RCA));

double **T1       =                       i_mR(RCA,RCA);
double **T2       =                       i_mR(RCA,RCA);

  clrscrn();
  printf(" If %+.0fx^2 %+.0fy^2 %+.0fxy = %+.0f \n\n"
         " Can you give a description of the curve in the plan?\n\n",
             A[R1][C1], A[R2][C2], 2*(A[R1][C2]), R);  

  printf(" A:");
  p_mR(A,S10,P4,C6);

  printf(" EVector:");
  p_mR(EVector,S10,P4,C6);

  printf(" EValue: EVectorT * A * EVector");      
  mul_mR(EVectorT,A,T1);
  mul_mR(T1,EVector,T2);
  p_mR(T2,S10,P4,C6);  
          
  Ev1Ev2 = (T2[R1][C1])*(T2[R2][C2]);
  
  if(Ev1Ev2 > 0)  
  
     printf(" The product of the eigenvalues = %+.3f > 0" 
            " give an ellipse or a circle.\n\n\n", 
         Ev1Ev2);
      
  else
     printf(" The product of the eigenvalues = %+.3f < 0" 
            " give an hyperbola.\n\n\n", 
         Ev1Ev2);

  printf(" %+.3f x^2 %+.3f y^2 = %+.3f \n\n",
             T2[R1][C1], T2[R2][C2], R);                          
  stop();
   
  f_mR(A);
  
  f_mR(EVector);
  f_mR(EVectorT);
   
  f_mR(T1);
  f_mR(T2);
  
  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */

Screen output example:

                                                                                       
 If +1x^2 +1y^2 +4xy = +3 

 Can you give a description of the curve in the plan?

 A:
   +1.0000    +2.0000 
   +2.0000    +1.0000 

 EVector:
   +0.7071    -0.7071 
   +0.7071    +0.7071 

 EValue: EVectorT * A * EVector
   +3.0000    +0.0000 
   +0.0000    -1.0000 

 The product of the eigenvalues = -3.000 < 0 give an hyperbola.


 +3.000 x^2 -1.000 y^2 = +3.000 

 Press return to continue.