Linear Algebra and the C Language/a09w
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as: c00a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
double **X_invgj_mR(
double **A,
double **invA
)
{
double **ID = i_RC_mR(A[R_SIZE][C0],A[C_SIZE][C0]);
double **AID;
int r = A[R_SIZE][C0];
r--;
AID = i_Abr_Ac_bc_mR(r,r,r);
eye_mR(ID); /* ID: Identity matrix */
c_A_b_Ab_mR(A,ID,AID); /* Copy A and ID into AID */
invgj_pivot_mR(AID); /* Work on the pivot */
sort_c_mR(AID); /* Sort the columns */
sort_r_mR(AID); /* Sort the rows */
c_Inv_A_mR(AID,invA); /* Copy the inverse into invA */
f_mR(AID);
f_mR(ID);
return(invA);
}
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r)
{
double **A = rE_mR( i_mR(r,r), 999.,1E-3);
double **InvA = i_mR(r,r);
clrscrn();
printf(" Copy/Paste into the octave window.\n\n");
printf("format short e\n");
p_Octave_mR(A,"A",P4);
printf(" inv(A)\n\n");
printf(" See above for the function code: invgj_mR();\n\n InvA:");
X_invgj_mR(A,InvA);
pE_mR(InvA, S12,P4,C6);
f_mR(InvA);
f_mR(A);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do
{
fun(C4);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Screen output example:
Copy/Paste into the octave window.
format short e
A=[
+0.8370,-0.0700,+0.5320,-0.7220;
+0.6970,+0.4480,+0.8980,-0.3510;
-0.2480,-0.1110,+0.6340,-0.2010;
-0.1730,+0.2510,+0.3120,+0.6670]
inv(A)
See above for the function code: invgj_mR();
InvA:
+1.6524e+00 -6.3813e-01 -1.0430e+00 +1.1386e+00
-2.7307e+00 +2.6376e+00 -5.8612e-01 -1.7444e+00
+5.4859e-01 -1.3496e-01 +9.1512e-01 +7.9858e-01
+1.1996e+00 -1.0949e+00 -4.7803e-01 +2.0775e+00
Press return to continue
Press X return to stop