Linear Algebra and the C Language/a0h3
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00c.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
void X_r_commute4_mR(
double **A,
double **B,
double **C,
double **E,
int n
)
{
double **P;
double **Pinv;
double **D;
double **T;
double **Dt;
int r=rsize_R(A);
P = i_mR(r,r);
Pinv = i_mR(r,r);
D = i_mR(r,r);
T = i_mR(r,r);
Dt = i_mR(r,r);
while(!det_R(r_mR(P,n)));
rdiag_mR(D,n);
inv_mR(P,Pinv);
mul_mR(P,Diag_sin_mR(D,Dt),T);
mul_mR(T,Pinv,A);
mul_mR(P,Diag_cos_mR(D,Dt),T);
mul_mR(T,Pinv,B);
mul_mR(P,Diag_sinh_mR(D,Dt),T);
mul_mR(T,Pinv,C);
mul_mR(P,Diag_cosh_mR(D,Dt),T);
mul_mR(T,Pinv,E);
f_mR(P);
f_mR(Pinv);
f_mR(D);
f_mR(T);
f_mR(Dt);
}
/* ------------------------------------ */
/* ------------------------------------ */
void AplsB(int r)
{
double **A = i_mR(r,r);
double **B = i_mR(r,r);
double **C = i_mR(r,r);
double **D = i_mR(r,r);
double **T = i_mR(r,r);
r_commute4_mR(A,B,C,D,9);
clrscrn();
printf(" A:");
p_mR(A, S5,P3,C6);
printf(" B:");
p_mR(B, S5,P3,C6);
printf(" C:");
p_mR(C, S5,P3,C6);
printf(" D:");
p_mR(D, S5,P3,C6);
stop();
clrscrn();
printf(" AB:");
p_mR(mul_mR(A,B,T), S5,P9,C6);
printf(" BA:");
p_mR(mul_mR(B,A,T), S5,P9,C6);
stop();
clrscrn();
printf(" AC:");
p_mR(mul_mR(A,C,T), S5,P9,C6);
printf(" CA:");
p_mR(mul_mR(C,A,T), S5,P9,C6);
stop();
clrscrn();
printf(" BC:");
p_mR(mul_mR(B,C,T), S5,P9,C6);
printf(" CB:");
p_mR(mul_mR(C,B,T), S5,P9,C6);
stop();
clrscrn();
printf(" AD:");
p_mR(mul_mR(A,D,T), S5,P9,C6);
printf(" DA:");
p_mR(mul_mR(D,A,T), S5,P9,C6);
stop();
clrscrn();
printf(" BD:");
p_mR(mul_mR(B,D,T), S5,P9,C6);
printf(" DB:");
p_mR(mul_mR(D,B,T), S5,P9,C6);
stop();
clrscrn();
printf(" CD:");
p_mR(mul_mR(C,D,T), S5,P9,C6);
printf(" DC:");
p_mR(mul_mR(D,C,T), S5,P9,C6);
f_mR(A);
f_mR(B);
f_mR(C);
f_mR(D);
f_mR(T);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do
{
AplsB(RC3);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Screen output example:
A:
+0.430 +0.559 +0.479
+0.672 -0.217 +1.387
+0.213 -0.248 +0.696
B:
-0.114 +0.000 -2.417
-0.806 +0.960 -1.813
-0.134 +0.000 +0.658
C:
+2.202 -0.099 +5.040
+1.589 +0.039 +3.598
+0.247 +0.044 +0.517
D:
+2.085 +0.000 +4.581
+1.527 +0.050 +3.436
+0.254 +0.000 +0.622
Press return to continue.
AB:
-0.563624018 +0.536572918 -1.737655344
-0.087723472 -0.208667246 -0.316616237
+0.082321231 -0.238476852 +0.393890016
BA:
-0.563624018 +0.536572918 -1.737655344
-0.087723472 -0.208667246 -0.316616237
+0.082321231 -0.238476852 +0.393890016
Press return to continue.
AC:
+1.953735877 -0.000000000 +4.427072993
+1.475690998 -0.013852121 +3.320304745
+0.245948500 +0.000000000 +0.539532004
CA:
+1.953735877 +0.000000000 +4.427072993
+1.475690998 -0.013852121 +3.320304745
+0.245948500 +0.000000000 +0.539532004
Press return to continue.
...