Linear Algebra and the C Language/a0kt
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as: c00c.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
double **X_invgj_pivot_mR(
double **Ab
)
{
double pivot = 1.;
int r= R1;
while( pivot &&
(r<Ab[R_SIZE ][C0])
)
{
pivot = pivotbestAId_mR(Ab,r); /* Select the best pivot */
if(pivot>ERROR_E)
zero_under_pivot_gj1Ab_mR(Ab,r); /* zero under the pivot */
r++;
}
while( (r>R1) )
{
r--;
zero_above_pivot_gj1Ab_mR(Ab,r); /* zero above the pivot */
}
return(Ab);
}
/* ------------------------------------ */
/* ------------------------------------ */
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);
c_A_b_Ab_mR(A,ID,AID);
X_invgj_pivot_mR(AID);
sort_c_mR(AID);
sort_r_mR(AID);
c_Inv_A_mR(AID,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();
X_invgj_mR(A,InvA);
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_pivot_mR();\n\n"
" 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.4020,+0.0880,+0.8280,-0.1620;
-0.0950,+0.6660,-0.3740,+0.8680;
-0.4290,+0.4750,+0.7460,+0.2280;
+0.9240,+0.3070,+0.5860,-0.9630]
inv(A)
See above for the function code: invgj_pivot_mR();
InvA:
+1.2509e+00 +6.1299e-01 -1.1382e+00 +7.2610e-02
-1.1435e+00 +6.1994e-01 +8.3469e-01 +9.4876e-01
+1.0051e+00 -2.3810e-01 +3.4312e-01 -3.0246e-01
+1.4474e+00 +6.4091e-01 -6.1717e-01 -8.5034e-01
Press return to continue
Press X return to stop