Linear Algebra and the C Language/a0p1


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00d.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */     
#define RCA          RC2  
/* ------------------------------------ */       
/* ------------------------------------ */
int main(void)
{                          
double a[RCA*RCA] ={   
+1.142857142857, +0.571428571428, 
-0.285714285714, -0.142857142857        
};

double P[RCA*C1] ={   
+3,
+1
};
                       
double **A  =  ca_A_mR(a, i_mR(RCA,RCA));
double **p  =  ca_A_mR(P, i_mR(RCA,C1));
double **Pp =             i_mR(RCA,C1);

  clrscrn();
  printf(" A :");
  p_mR(A, S9,P12, C4); 
  
  printf(" p: A point of the plan");
  p_mR(p, S9,P12, C4); 
 
  printf(" Pp: The projection of p on the line");
  mul_mR(A,p,Pp);
  p_mR(Pp, S9,P12, C4);      
  stop();
 
  f_mR(A);
  f_mR(p);
  f_mR(Pp);
  
  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
You can calculate the projection of a point P onto the line. You can draw a cartesian coordinate system to verify the result for P(-5,3), P(3,1),  P(-1,2)
 

Screen output example:

                                                                                       
 A :
+1.142857142857 +0.571428571428 
-0.285714285714 -0.142857142857 

 p: A point of the plan
     -5.0 
     +3.0 

 Pp: The projection of p on the line
     -4.0 
     +1.0 

 Press return to continue.