Linear Algebra and the C Language/a0h1
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
double **X_Diag_sin_mR(
double **A,
double **sinA)
{
int r;
int c;
m0_mR(sinA);
for (r=R1; r<A[R_SIZE][C0]; r++)
for (c=C1; c<A[C_SIZE][C0]; c++)
if(r==c) sinA[r][c] = sin(A[r][c]);
return(sinA);
}
/* ------------------------------------ */
/* ------------------------------------ */
double **X_Diag_cos_mR(
double **A,
double **cosA)
{
int r;
int c;
m0_mR(cosA);
for (r=R1; r<A[R_SIZE][C0]; r++)
for (c=C1; c<A[C_SIZE][C0]; c++)
if(r==c) cosA[r][c]=cos(A[r][c]);
return(cosA);
}
/* ------------------------------------ */
/* ------------------------------------ */
void X_r_commute2_mR(
double **A,
double **B,
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);
f_mR(P);
f_mR(Pinv);
f_mR(D);
f_mR(T);
f_mR(Dt);
}
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r)
{
double **A = i_mR(r,r);
double **B = i_mR(r,r);
double **T = i_mR(r,r);
r_commute2_mR(A,B,9);
clrscrn();
printf(" A:");
p_mR(A,S5,P3,C6);
printf(" B:");
p_mR(B, S5,P3,C6);
stop();
clrscrn();
printf(" AB:");
mul_mR(A,B,T);
p_mR(T, S8,P3,C6);
printf(" BA:");
mul_mR(B,A,T);
p_mR(T, S8,P3,C6);
f_mR(A);
f_mR(B);
f_mR(T);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do
{
fun(RC4);
} while(stop_w());
return 0;
}
/*------------------------------------ */
/* ----------------------------------- */
Screen output example:
A:
+1.310 +1.334 -3.028 -1.497
+0.548 +0.688 -1.112 -0.022
+1.108 +0.920 -2.866 -1.148
-1.162 -0.494 +2.795 +1.413
B:
-0.534 -1.190 +2.360 +1.374
-0.590 -0.288 +0.423 -0.337
-0.572 -0.367 +1.476 +0.537
+0.387 -0.531 -0.555 -0.223
Press return to continue.
AB:
-0.334 -0.037 +0.018 +0.058
-0.071 -0.430 -0.046 -0.072
+0.061 +0.078 -0.588 -0.071
-0.141 -0.251 +0.389 -0.244
BA:
-0.334 -0.037 +0.018 +0.058
-0.071 -0.430 -0.046 -0.072
+0.061 +0.078 -0.588 -0.071
-0.141 -0.251 +0.389 -0.244
Press return to continue
Press X return to stop