411 REFERENCE · Wikibooks
Linear Algebra and the C Language/a0nl
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
__NOTOC__
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as: c00a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r,int rc)
{
double **A = r_mR( i_mR(r,rc),99);
double **At = transpose_mR(A, i_mR(rc,r));
double **AAt = mul_mR(A,At, i_mR(r, r));
clrscrn();
printf(" A[R%d,C%d]: \n",rsize_R(A),csize_R(A));
p_mR(A, S4,P0, C4);
printf(" At[R%d,C%d]: Transpose\n",
rsize_R(At),csize_R(At));
p_mR(At, S4,P0, C4);
printf(" AAt[R%d,C%d]: \n",rsize_R(AAt),csize_R(AAt));
p_mR(AAt, S7,P0, C4);
f_mR(A);
f_mR(At);
f_mR(AAt);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do
fun(rp_I(R4),rp_I(RC4));
while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Multiplying A by its transpose gives a symmetric matrix
Screen output example:
A[R3,C4]:
-42 +43 +62 +71
-11 +35 -57 -88
-67 +97 +56 +58
At[R4,C3]: Transpose
-42 -11 -67
+43 +35 +97
+62 -57 +56
+71 -88 +58
AAt[R3,C3]:
+12498 -7815 +14575
-7815 +12339 -4164
+14575 -4164 +20398
Press return to continue
Press X return to stop