Mathc matrices/c30e
Installer et compiler ces fichiers dans votre répertoire de travail.
c02b.c |
---|
/* ------------------------------------ */
/* Save as : c2b.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
int main(void)
{
double a[R4*C8]={
1, 3, 2, 3, 1,0,0,0,
9, 1, 1, 2, 0,1,0,0,
2, 3, 8, 5, 0,0,1,0,
3, 4, 8, 1, 0,0,0,1,
};
double inva[R4*C4]={
-403./9789., +1118./9789., -247./9789., +208./9789.,
+3783./9789., -390./9789., -2418./9789., +1521./9789.,
-1846./9789., -247./9789., +1079./9789., +637./9789.,
+845./9789., +182./9789., +1781./9789., -2015./9789.
};
double **A = ca_A_mR(a, i_mR(R4,C8));
double **invA = ca_A_mR(inva,i_mR(R4,C4));
double **T = i_mR(R4,C4);
int i = 1;
/* 1-----------------------------------
+1 +3 +2 +3 +1 +0 +0 +0
+9 +1 +1 +2 +0 +1 +0 +0
+2 +3 +8 +5 +0 +0 +1 +0
+3 +4 +8 +1 +0 +0 +0 +1
------------------------------------ */
clrscrn();
printf(" (%d) \n\n",i++);
p_mR(A,S8,P0,C8);
printf(" R2 = -9*R1 + R2 \n");addR_mR(A, -9,R1,R2);
printf(" R3 = -2*R1 + R3 \n");addR_mR(A, -2,R1,R3);
printf(" R4 = -3*R1 + R4 \n");addR_mR(A, -3,R1,R4);
p_mR(A,S8,P0,C8);
stop();
/* 1-----------------------------------
+1 +3 +2 +3 +1 +0 +0 +0
+0 -26 -17 -25 -9 +1 +0 +0
+0 -3 +4 -1 -2 +0 +1 +0
+0 -5 +2 -8 -3 +0 +0 +1
------------------------------------ */
clrscrn();
printf(" (%d) \n\n",i++);
p_mR(A,S8,P0,C8);
printf(" R3 = -26*R3 \n"); mulR_mR(A,-26.,R3);
printf(" R4 = -26*R4 \n"); mulR_mR(A,-26.,R4);
printf(" R3 = 3*R2 + R3 \n");addR_mR(A, 3.,R2,R3);
printf(" R4 = 5*R2 + R4 \n");addR_mR(A, 5.,R2,R4);
p_mR(A,S8,P0,C8);
stop();
/* 1-----------------------------------
+1 +3 +2 +3 +1 +0 +0 +0
+0 -26 -17 -25 -9 +1 +0 +0
+0 +0 -155 -49 +25 +3 -26 +0
+0 +0 -137 +83 +33 +5 +0 -26
------------------------------------ */
clrscrn();
printf(" (%d) \n\n",i++);
p_mR(A,S8,P0,C8);
printf(" R4 = -155*R4 \n"); mulR_mR(A,-155.,R4);
printf(" R4 = 137*R3 + R4 \n");addR_mR(A, 137.,R3,R4);
p_mR(A,S8,P0,C8);
stop();
/* 1-----------------------------------
+1 +3 +2 +3 +1 +0 +0 +0
+0 -26 -17 -25 -9 +1 +0 +0
+0 +0 -155 -49 +25 +3 -26 +0
+0 +0 +0 -19578 -1690 -364 -3562 +4030
------------------------------------ */
clrscrn();
printf(" (%d) \n\n",i++);
p_mR(A,S8,P0,C8);
printf(" R4 = 1./2.*R4 \n");mulR_mR(A,1./2.,R4);
p_mR(A,S8,P0,C8);
stop();
/* 1-----------------------------------
+1 +3 +2 +3 +1 +0 +0 +0
+0 -26 -17 -25 -9 +1 +0 +0
+0 +0 -155 -49 +25 +3 -26 +0
+0 +0 +0 -9789 -845 -182 -1781 +2015
------------------------------------ */
clrscrn();
printf(" (%d) \n\n",i++);
p_mR(A,S8,P0,C8);
printf(" R1 = -9789.*R1 \n"); mulR_mR(A,-9789.,R1);
printf(" R2 = -9789.*R2 \n"); mulR_mR(A,-9789.,R2);
printf(" R3 = -9789.*R3\n\n"); mulR_mR(A,-9789.,R3);
printf(" R1 = -3*R4 + R1 \n");addR_mR(A, -3.,R4,R1);
printf(" R2 = 25*R4 + R2 \n");addR_mR(A, 25.,R4,R2);
printf(" R3 = 49*R4 + R3 \n");addR_mR(A, 49.,R4,R3);
p_mR(A,S8,P0,C8);
stop();
/* 1-----------------------------------
-9789 -29367 -19578 +0 -7254 +546 +5343 -6045
+0 +254514 +166413 +0 +66976 -14339 -44525 +50375
+0 +0 +1517295 +0 -286130 -38285 +167245 +98735
+0 +0 +0 -9789 -845 -182 -1781 +2015
------------------------------------ */
clrscrn();
printf(" (%d) \n\n",i++);
p_mR(A,S8,P0,C8);
printf(" R3 = -1./155.*R3 \n");mulR_mR(A,-1./155.,R3);
p_mR(A,S8,P0,C8);
stop();
/* 1-----------------------------------
-9789 -29367 -19578 +0 -7254 +546 +5343 -6045
+0 +254514 +166413 +0 +66976 -14339 -44525 +50375
-0 -0 -9789 -0 +1846 +247 -1079 -637
+0 +0 +0 -9789 -845 -182 -1781 +2015
------------------------------------ */
clrscrn();
printf(" (%d) \n\n",i++);
p_mR(A,S8,P0,C8);
printf(" R1 = -2*R3 + R1 ( 2*9789 = 19578)\n");addR_mR(A, -2.,R3,R1);
printf(" R2 = +17*R3 + R2 (17*9789 = 166413)\n");addR_mR(A,+17.,R3,R2);
p_mR(A,S8,P0,C8);
stop();
/* 1-----------------------------------
-9789 -29367 +0 +0 -10946 +52 +7501 -4771
+0 +254514 +0 +0 +98358 -10140 -62868 +39546
-0 -0 -9789 -0 +1846 +247 -1079 -637
+0 +0 +0 -9789 -845 -182 -1781 +2015
------------------------------------ */
clrscrn();
printf(" (%d) \n\n",i++);
p_mR(A,S8,P0,C8);
printf(" R2 = -1./26.*R2 \n");mulR_mR(A,-1./26.,R2);
p_mR(A,S8,P0,C8);
stop();
/* 1-----------------------------------
-9789 -29367 +0 +0 -10946 +52 +7501 -4771
-0 -9789 -0 -0 -3783 +390 +2418 -1521
-0 -0 -9789 -0 +1846 +247 -1079 -637
+0 +0 +0 -9789 -845 -182 -1781 +2015
------------------------------------ */
clrscrn();
printf(" (%d) \n\n",i++);
p_mR(A,S8,P0,C8);
printf(" R1 =-3*R2 + R1 (3*-9789 = 29367) \n");addR_mR(A,-3.,R2,R1);
p_mR(A,S8,P0,C8);
stop();
/* 1-----------------------------------
-9789 +0 +0 +0 +403 -1118 +247 -208
-0 -9789 -0 -0 -3783 +390 +2418 -1521
-0 -0 -9789 -0 +1846 +247 -1079 -637
+0 +0 +0 -9789 -845 -182 -1781 +2015
------------------------------------ */
clrscrn();
printf(" A : ");
ca_A_mR(a, A);
p_mR(A,S11,P5,C4);
printf(" A : inv_mR(invA, T); [see : double inva[R4*C4] ]");
inv_mR(invA, T);
p_mR(T, S11, P2, C6);
stop();
f_mR(A);
f_mR(invA);
f_mR(T);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Le but de ces exemples est d'inverser une matrice sans faire apparaître de fraction. La matrice double inva[R4*C4] donne le résultat calculé dans le fichier et permet de vérifier que inv(invA) = A.
Exemple de sortie écran :
------------------------------------
(1)
+1 +3 +2 +3 +1 +0 +0 +0
+9 +1 +1 +2 +0 +1 +0 +0
+2 +3 +8 +5 +0 +0 +1 +0
+3 +4 +8 +1 +0 +0 +0 +1
R2 = -9*R1 + R2
R3 = -2*R1 + R3
R4 = -3*R1 + R4
+1 +3 +2 +3 +1 +0 +0 +0
+0 -26 -17 -25 -9 +1 +0 +0
+0 -3 +4 -1 -2 +0 +1 +0
+0 -5 +2 -8 -3 +0 +0 +1
Press return to continue.
------------------------------------
(2)
+1 +3 +2 +3 +1 +0 +0 +0
+0 -26 -17 -25 -9 +1 +0 +0
+0 -3 +4 -1 -2 +0 +1 +0
+0 -5 +2 -8 -3 +0 +0 +1
R3 = -26*R3
R4 = -26*R4
R3 = 3*R2 + R3
R4 = 5*R2 + R4
+1 +3 +2 +3 +1 +0 +0 +0
+0 -26 -17 -25 -9 +1 +0 +0
+0 +0 -155 -49 +25 +3 -26 +0
+0 +0 -137 +83 +33 +5 +0 -26
Press return to continue.
------------------------------------
(3)
+1 +3 +2 +3 +1 +0 +0 +0
+0 -26 -17 -25 -9 +1 +0 +0
+0 +0 -155 -49 +25 +3 -26 +0
+0 +0 -137 +83 +33 +5 +0 -26
R4 = -155*R4
R4 = 137*R3 + R4
+1 +3 +2 +3 +1 +0 +0 +0
+0 -26 -17 -25 -9 +1 +0 +0
+0 +0 -155 -49 +25 +3 -26 +0
+0 +0 +0 -19578 -1690 -364 -3562 +4030
Press return to continue.
------------------------------------
(4)
+1 +3 +2 +3 +1 +0 +0 +0
+0 -26 -17 -25 -9 +1 +0 +0
+0 +0 -155 -49 +25 +3 -26 +0
+0 +0 +0 -19578 -1690 -364 -3562 +4030
R4 = 1./2.*R4
+1 +3 +2 +3 +1 +0 +0 +0
+0 -26 -17 -25 -9 +1 +0 +0
+0 +0 -155 -49 +25 +3 -26 +0
+0 +0 +0 -9789 -845 -182 -1781 +2015
Press return to continue.
------------------------------------
(5)
+1 +3 +2 +3 +1 +0 +0 +0
+0 -26 -17 -25 -9 +1 +0 +0
+0 +0 -155 -49 +25 +3 -26 +0
+0 +0 +0 -9789 -845 -182 -1781 +2015
R1 = -9789.*R1
R2 = -9789.*R2
R3 = -9789.*R3
R1 = -3*R4 + R1
R2 = 25*R4 + R2
R3 = 49*R4 + R3
-9789 -29367 -19578 +0 -7254 +546 +5343 -6045
+0 +254514 +166413 +0 +66976 -14339 -44525 +50375
+0 +0 +1517295 +0 -286130 -38285 +167245 +98735
+0 +0 +0 -9789 -845 -182 -1781 +2015
Press return to continue.
------------------------------------
(6)
-9789 -29367 -19578 +0 -7254 +546 +5343 -6045
+0 +254514 +166413 +0 +66976 -14339 -44525 +50375
+0 +0 +1517295 +0 -286130 -38285 +167245 +98735
+0 +0 +0 -9789 -845 -182 -1781 +2015
R3 = -1./155.*R3
-9789 -29367 -19578 +0 -7254 +546 +5343 -6045
+0 +254514 +166413 +0 +66976 -14339 -44525 +50375
-0 -0 -9789 -0 +1846 +247 -1079 -637
+0 +0 +0 -9789 -845 -182 -1781 +2015
Press return to continue.
------------------------------------
(7)
-9789 -29367 -19578 +0 -7254 +546 +5343 -6045
+0 +254514 +166413 +0 +66976 -14339 -44525 +50375
-0 -0 -9789 -0 +1846 +247 -1079 -637
+0 +0 +0 -9789 -845 -182 -1781 +2015
R1 = -2*R3 + R1 ( 2*9789 = 19578)
R2 = +17*R3 + R2 (17*9789 = 166413)
-9789 -29367 +0 +0 -10946 +52 +7501 -4771
+0 +254514 +0 +0 +98358 -10140 -62868 +39546
-0 -0 -9789 -0 +1846 +247 -1079 -637
+0 +0 +0 -9789 -845 -182 -1781 +2015
Press return to continue.
------------------------------------
(8)
-9789 -29367 +0 +0 -10946 +52 +7501 -4771
+0 +254514 +0 +0 +98358 -10140 -62868 +39546
-0 -0 -9789 -0 +1846 +247 -1079 -637
+0 +0 +0 -9789 -845 -182 -1781 +2015
R2 = -1./26.*R2
-9789 -29367 +0 +0 -10946 +52 +7501 -4771
-0 -9789 -0 -0 -3783 +390 +2418 -1521
-0 -0 -9789 -0 +1846 +247 -1079 -637
+0 +0 +0 -9789 -845 -182 -1781 +2015
Press return to continue.
------------------------------------
(9)
-9789 -29367 +0 +0 -10946 +52 +7501 -4771
-0 -9789 -0 -0 -3783 +390 +2418 -1521
-0 -0 -9789 -0 +1846 +247 -1079 -637
+0 +0 +0 -9789 -845 -182 -1781 +2015
R1 =-3*R2 + R1 (3*-9789 = 29367)
-9789 +0 +0 +0 +403 -1118 +247 -208
-0 -9789 -0 -0 -3783 +390 +2418 -1521
-0 -0 -9789 -0 +1846 +247 -1079 -637
+0 +0 +0 -9789 -845 -182 -1781 +2015
Press return to continue.
------------------------------------
A :
+1.00000 +3.00000 +2.00000 +3.00000
+9.00000 +1.00000 +1.00000 +2.00000
+2.00000 +3.00000 +8.00000 +5.00000
+3.00000 +4.00000 +8.00000 +1.00000
+1.00000 +0.00000 +0.00000 +0.00000
+0.00000 +1.00000 +0.00000 +0.00000
+0.00000 +0.00000 +1.00000 +0.00000
+0.00000 +0.00000 +0.00000 +1.00000
A : inv_mR(invA, T); [see : double inva[R4*C4] ]
+1.00 +3.00 +2.00 +3.00
+9.00 +1.00 +1.00 +2.00
+2.00 +3.00 +8.00 +5.00
+3.00 +4.00 +8.00 +1.00
Press return to continue.