Linear Algebra and the C Language/a0cf


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00a.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define RCA      RC4
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
{  
    
double **A           = rEsymmetric_mR(i_mR(RCA,RCA),999,+1.E-3);  

double **ExpA_EValue = i_mR(RCA,RCA);
double **ExpA        = i_mR(RCA,RCA);

double **Log_ExpA_EValue = i_mR(RCA,RCA); 
double **Log_ExpA        = i_mR(RCA,RCA);
    
double **V       = i_mR(RCA,RCA);
double **V_T     = i_mR(RCA,RCA);
double **EValue  = i_mR(RCA,RCA); 
double **T       = i_mR(RCA,RCA);

/* ================================================================== */           
   clrscrn();
   printf(" Copy/Paste into the octave window.       \n\n");
   p_Octave_mR(A, "A", P6);
   printf(" expm (A)\n\n\n");
  
   eigs_V_mR(A,V);
   transpose_mR(V,V_T);
    
/* EValue = V_T * A * V */   
   mul_mR(V_T,A,T);
   mul_mR(T,V,EValue); 
    
   printf(" ExpA");
   f_eigs_mR(exp,EValue, ExpA_EValue);   
      mul_mR(V,ExpA_EValue,T);
      mul_mR(T,V_T,ExpA);
        p_mR(ExpA, S9,P4, C6);
   stop();

/* ================================================================== */   
   clrscrn();     
   printf(" Copy/Paste into the octave window.       \n\n");
   p_Octave_mR(ExpA,"ExpA", P6);
   printf(" logm (ExpA)\n\n\n");
  
   eigs_V_mR(ExpA,V);
   transpose_mR(V,V_T);
    
/* ExpA_EValue = V_T * ExpA * V */   
   mul_mR(V_T,ExpA,T);
   mul_mR(T,V,ExpA_EValue); 
   
   printf(" Log_ExpA = A");
   f_eigs_mR(log,ExpA_EValue, Log_ExpA_EValue);     
      mul_mR(V,Log_ExpA_EValue,T);
      mul_mR(T,V_T,Log_ExpA);
        p_mR(Log_ExpA, S9,P6, C6);
 
    printf(" A :");
    p_mR(A, S9,P6, C6);
    stop();
     
   f_mR(A);
   
   f_mR(ExpA_EValue);
   f_mR(ExpA);
    
   f_mR(Log_ExpA_EValue);
   f_mR(Log_ExpA); 
      
   f_mR(V);
   f_mR(V_T);
   f_mR(EValue); 
   f_mR(T);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
    fun();
    
} while(stop_w());

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


Screen output example:

                                                                                       
 Copy/Paste into the octave window.       

 A=[
+1.540478,+0.012149,-1.424911,-1.181580;
+0.012149,+1.158342,-0.449479,-0.364186;
-1.424911,-0.449479,+1.875695,+1.228040;
-1.181580,-0.364186,+1.228040,+1.327935]

 expm (A)


 ExpA
 +22.7443   +5.2247  -24.1095  -19.5833 
  +5.2247   +4.6660   -6.7998   -5.5033 
 -24.1095   -6.7998  +28.6119  +22.0349 
 -19.5833   -5.5033  +22.0349  +19.2602 

 Press return to continue. 


 Copy/Paste into the octave window.       

 ExpA=[
+22.744333,+5.224660,-24.109487,-19.583281;
+5.224660,+4.666045,-6.799824,-5.503329;
-24.109487,-6.799824,+28.611896,+22.034878;
-19.583281,-5.503329,+22.034878,+19.260246]

 logm (ExpA)


 Log_ExpA = A
+1.540478 +0.012149 -1.424911 -1.181580 
+0.012149 +1.158342 -0.449479 -0.364186 
-1.424911 -0.449479 +1.875695 +1.228040 
-1.181580 -0.364186 +1.228040 +1.327935 

 A :
+1.540478 +0.012149 -1.424911 -1.181580 
+0.012149 +1.158342 -0.449479 -0.364186 
-1.424911 -0.449479 +1.875695 +1.228040 
-1.181580 -0.364186 +1.228040 +1.327935 

 Press return to continue.