Linear Algebra and the C Language/a0fe
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
void X_c_Inv_A_mR(
double **AID,
double **invA
)
{
int r;
int c;
int RC = AID[C_SIZE_A][C0];
--RC;
for (r=R1; r<invA[R_SIZE][C0]; r++)
for (c=C1; c<invA[C_SIZE][C0]; c++)
invA[r][c] = AID[r][c+RC];
}
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r)
{
double **A = i_mR(r,r);
double **b = i_mR(r,r);
double **Ab = i_Abr_Ac_bc_mR( r, r, r);
/* i_Abr_Ac_bc_mR(R_Ab,C_A,C_b)); */
double **invA = i_mR(r,r);
do
{
r_mR(A,999.);
printf(".");
}while(!det_R(A));
clrscrn();
printf(" A :");
p_mR(A, S8,P0,C4);
printf(" b : ID :");
eye_mR(b);
p_mR(b, S8,P0,C4);
stop();
clrscrn();
printf(" Ab :");
c_A_b_Ab_mR(A,b,Ab);
p_mR(Ab, S8,P0,C4);
printf(" gj_TP_mR(Ab) :");
gj_TP_mR(Ab);
p_mR(Ab, S8,P4,C4);
stop();
clrscrn();
printf(" Copy/Past into the octave window.\n\n");
p_Octave_mR(A,"A",P0);
printf("format short e\n");
printf(" inv(A)\n\n");
printf(" invA : c_Inv_A_mR(Ab,invA);");
c_Inv_A_mR(Ab,invA);
pE_mR(invA, S14,P4,C4);
f_mR(invA);
f_mR(Ab);
f_mR(b);
f_mR(A);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do
{
fun(R4);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Copy b of the system Ab into the matrix invA:
Screen output example:
A :
+498 -467 -231 +109
-835 +153 +787 -191
-217 -939 -379 +418
+888 -337 +608 -150
b : ID :
+1 +0 +0 +0
+0 +1 +0 +0
+0 +0 +1 +0
+0 +0 +0 +1
Press return to continue.
Ab :
+498 -467 -231 +109
-835 +153 +787 -191
-217 -939 -379 +418
+888 -337 +608 -150
+1 +0 +0 +0
+0 +1 +0 +0
+0 +0 +1 +0
+0 +0 +0 +1
gj_TP_mR(Ab) :
+1.0000 +0.0000 +0.0000 +0.0000
+0.0000 +1.0000 +0.0000 +0.0000
+0.0000 +0.0000 +1.0000 +0.0000
-0.0000 -0.0000 -0.0000 +1.0000
-0.0017 -0.0012 +0.0003 +0.0011
-0.0057 -0.0022 +0.0009 +0.0013
-0.0052 -0.0012 +0.0016 +0.0022
-0.0185 -0.0067 +0.0061 +0.0055
Press return to continue.
Copy/Past into the octave window.
A=[
+498,-467,-231,+109;
-835,+153,+787,-191;
-217,-939,-379,+418;
+888,-337,+608,-150]
format short e
inv(A)
invA : c_Inv_A_mR(Ab,invA);
-1.7278e-03 -1.1824e-03 +2.8845e-04 +1.0538e-03
-5.7200e-03 -2.2488e-03 +9.3871e-04 +1.3227e-03
-5.2021e-03 -1.1816e-03 +1.6056e-03 +2.1986e-03
-1.8463e-02 -6.7368e-03 +6.1066e-03 +5.5119e-03
Press return to continue
Press X return to stop