Linear Algebra and the C Language/a0ho
The Maclaurin series of the exponential function is :
Exp(A) = Ide + A + (1/2) A2 + (1/6) A3 + ... + 1/(n-1)! A(n-1)
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define RCA RC4
/* ------------------------------------ */
void fun(void)
{
int n = 10;
int i = 0;
double **A = rE_mR(i_mR(RCA,RCA),999,+1.E-3);
double **A_n = i_mR(RCA,RCA);
double **sA = i_mR(RCA,RCA);
double **ExpA = i_mR(RCA,RCA);
double **NewExpA = i_mR(RCA,RCA);
clrscrn();
printf(" Copy/Paste into the octave window. \n\n");
p_Octave_mR(A, "A", P3);
printf(" expm (A)\n\n\n");
for(i = 0; i <= n; i++)
{
pow_mR(i, A, A_n);
smul_mR(1./factorial(i), A_n, sA);
add_mR(ExpA,sA,NewExpA);
c_mR(NewExpA,ExpA);
}
printf(" ExpA:");
p_mR(ExpA, S8,P6,C6);
f_mR(A);
f_mR(A_n);
f_mR(sA);
f_mR(ExpA);
f_mR(NewExpA);
}
/* ------------------------------------ */
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=[
-0.558,-0.021,+0.564,+0.427;
-0.744,-0.187,-0.364,-0.179;
-0.685,-0.860,+0.232,+0.477;
+0.772,-0.785,+0.716,+0.690]
expm (A)
ExpA:
+0.6789 -0.5183 +0.8022 +0.7396
-0.5620 +1.2442 -0.7696 -0.6063
-0.0998 -1.2209 +1.6398 +0.8534
+1.0577 -1.7851 +1.8591 +2.7969
Press return to continue
Press X return to stop