Mathc matrices/c23o
Application ou Résoudre avec ... 
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c00p.c */
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
double xy[8] ={
 1, 1,
 2, 4,
 3, 9,
 4, 16 };
double ab[RA*(CA+Cb)]={
/* x**2 y**2 x y e = 0 */
 +1.00, +0.00, +0.00, +0.00, +0.00, +1.00, 
 +1.00, +1.00, +1.00, +1.00, +1.00, +0.00, 
 +4.00, +16.00, +2.00, +4.00, +1.00, +0.00, 
 +9.00, +81.00, +3.00, +9.00, +1.00, +0.00, 
 +16.00, +256.00, +4.00, +16.00, +1.00, +0.00 
double **XY = ca_A_mR(xy,i_mR(R4,C2));
double **Ab = ca_A_mR(ab,i_Abr_Ac_bc_mR(RA,CA,Cb));
double **A = c_Ab_A_mR(Ab,i_mR(RA,CA));
double **b = c_Ab_b_mR(Ab,i_mR(RA,Cb));
double **A_T = i_mR(CA,RA);
double **A_TA = i_mR(CA,CA); // A_T*A
double **invA_TA = i_mR(CA,CA); // inv(A_T*A)
double **invA_TAA_T = i_mR(CA,RA); // inv(A_T*A)*A_T
double **x = i_mR(CA,Cb); // x = inv(A_T*A)*A_T*b
 clrscrn();
 printf("\n");
 printf(" Find the coefficients a, b, c, d, e, of the curve \n\n");
 printf(" ax**2 + by**2 + cx + dy + e = 0 \n\n");
 printf(" that passes through these four points.\n\n");
 printf(" x y");
 p_mR(XY,S5,P0,C6);
 printf(" Using the given points, we obtain this matrix.\n");
 printf(" (a = 1. This is my choice)\n\n"); 
 printf(" Ab :\n");
 printf(" x**2 y**2 x y e = 0 ");
 p_mR(Ab,S7,P2,C6);
 stop();
 clrscrn();
 printf(" A_T :");
 p_mR(transpose_mR(A,A_T),S10,P2,C7);
 printf(" A_TA :");
 p_mR(mul_mR(A_T,A,A_TA),S10,P2,C7);
 stop();
 clrscrn();
 printf(" inv(A_TA) :");
 p_mR(inv_mR(A_TA,invA_TA),S10,P4,C7); 
 printf(" inv(A_TA)*A_T :");
 p_mR(mul_mR(invA_TA,A_T,invA_TAA_T),S10,P4,C7);
 printf("\n x = inv(A_TA)*A_T*b :");
 p_mR(mul_mR(invA_TAA_T,b,x),S10,P4,C7);
 stop();
 clrscrn();
 printf("\n x = inv(A_TA)*A_T*b :");
 p_mR(x,S10,P2,C7); 
 printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
 " %+.2fx**2 %+.2fy = 0\n\n"
 ,x[R1][C1],x[R4][C1]); 
 stop(); 
 f_mR(XY); 
 f_mR(A);
 f_mR(b);
 f_mR(Ab);
 f_mR(A_T);
 f_mR(A_TA); // A_T*A
 f_mR(invA_TA); // inv(A_T*A)
 f_mR(invA_TAA_T); // inv(A_T*A)*A_T
 f_mR(x); 
/* ------------------------------------ */
int main(void)

fun();
 return 0;
/* ------------------------------------ */
 Trouver les coefficients a, b, c, d, e du conique,
 ax**2 + by**2 + cx + dy + e = 0 
 qui passe par ces quatre points. 
 (x[1],y[1]) (x[2],y[2]) (x[3],y[3]) (x[4],y[4]) 
 En utilisant les quatre points nous obtenons la matrice.
 (a)x**2 (b)y**2 (c)x (d)y (e) = 0 
 x[1]**2 y[1]**2 x[1] y[1] 1 0
 x[2]**2 y[2]**2 x[2] y[2] 1 0
 x[3]**2 y[3]**2 x[3] y[3] 1 0
 x[4]**2 y[4]**2 x[4] y[4] 1 0
 Ce système à quatre lignes et cinq inconnus (a, b, c, d, e).
 C'est un système homogène, il a donc une infinité de solution.
 Pour trouver une solution j'ai choisi de poser que a = 1.
 Nous avons donc cinq lignes et cinq inconnus.
 1 0 0 0 0 1 
 x[1]**2 y[1]**2 x[1] y[1] 1 0 
 x[2]**2 y[2]**2 x[2] y[2] 1 0 
 x[3]**2 y[3]**2 x[3] y[3] 1 0 
 x[4]**2 y[4]**2 x[4] y[4] 1 0 
 Il suffit maintenant de résoudre le système.

Exemple de sortie écran :
 Find the coefficients a, b, c, d, e, of the curve 
 ax**2 + by**2 + cx + dy + e = 0 
 that passes through these four points.
 x y
 +1 +1 
 +2 +4 
 +3 +9 
 +4 +16 
 Using the given points, we obtain this matrix.
 (a = 1. This is my choice)
 Ab :
 x**2 y**2 x y e = 0 
 +1.00 +0.00 +0.00 +0.00 +0.00 +1.00 
 +1.00 +1.00 +1.00 +1.00 +1.00 +0.00 
 +4.00 +16.00 +2.00 +4.00 +1.00 +0.00 
 +9.00 +81.00 +3.00 +9.00 +1.00 +0.00 
 +16.00 +256.00 +4.00 +16.00 +1.00 +0.00 
 Press return to continue. 
 -----------------------------------
 A_T :
 +1.00 +1.00 +4.00 +9.00 +16.00 
 +0.00 +1.00 +16.00 +81.00 +256.00 
 +0.00 +1.00 +2.00 +3.00 +4.00 
 +0.00 +1.00 +4.00 +9.00 +16.00 
 +0.00 +1.00 +1.00 +1.00 +1.00 
 A_TA :
 +355.00 +4890.00 +100.00 +354.00 +30.00 
 +4890.00 +72354.00 +1300.00 +4890.00 +354.00 
 +100.00 +1300.00 +30.00 +100.00 +10.00 
 +354.00 +4890.00 +100.00 +354.00 +30.00 
 +30.00 +354.00 +10.00 +30.00 +4.00 
 Press return to continue. 
 -----------------------------------
 inv(A_TA) :
 +1.0000 +0.0000 +0.0000 -1.0000 -0.0000 
 +0.0000 +0.0056 +0.6500 -0.2222 -0.4500 
 +0.0000 +0.6500 +82.5000 -27.2500 -59.4000 
 -1.0000 -0.2222 -27.2500 +10.1389 +19.2500 
 -0.0000 -0.4500 -59.4000 +19.2500 +44.2000 
 inv(A_TA)*A_T :
 +1.0000 +0.0000 +0.0000 +0.0000 +0.0000 
 +0.0000 -0.0167 +0.0500 -0.0500 +0.0167 
 +0.0000 -3.5000 +7.0000 -4.5000 +1.0000 
 -1.0000 +0.9167 -2.2500 +1.7500 -0.4167 
 +0.0000 +3.6000 -4.8000 +2.8000 -0.6000 
 x = inv(A_TA)*A_T*b :
 +1.0000 
 +0.0000 
 +0.0000 
 -1.0000 
 +0.0000 
 Press return to continue. 
 -----------------------------------
 x = inv(A_TA)*A_T*b :
 +1.00 
 +0.00 
 +0.00 
 -1.00 
 +0.00 
 The coefficients a, b, c, d, e, of the curve are : 
 +1.00x**2 -1.00y = 0
 Press return to continue.

Mathc matrices/c23p
Application ou QR décomposition
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c00r.c */
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
double xy[6] ={
 1, -2,
 2, -3,
 3, 6 };
double ab[RA*(CA+Cb)]={
/* x**2 y**2 x y e = 0 */
 +1.00, +0.00, +0.00, +0.00, +0.00, +1.00, 
 +0.00, +1.00, +0.00, +0.00, +0.00, +1.00, 
 +1.00, +4.00, +1.00, -2.00, +1.00, +0.00, 
 +4.00, +9.00, +2.00, -3.00, +1.00, +0.00, 
 +9.00, +36.00, +3.00, +6.00, +1.00, +0.00, 
double **XY = ca_A_mR(xy,i_mR(R3,C2));
double **Ab = ca_A_mR(ab,i_Abr_Ac_bc_mR(RA,CA,Cb));
double **A = c_Ab_A_mR(Ab,i_mR(RA,CA));
double **b = c_Ab_b_mR(Ab,i_mR(RA,Cb));
double **Q = i_mR(RA,CA);
double **R = i_mR(CA,CA);
double **invR = i_mR(CA,CA);
double **Q_T = i_mR(CA,RA);
double **invR_Q_T = i_mR(CA,RA);
double **x = i_mR(CA,Cb); // x invR * Q_T * b
 clrscrn();
 printf("\n");
 printf(" Find the coefficients a, b, c, d, of a circle \n\n");
 printf(" ax**2 + ay**2 + bx + cy + d = 0 \n\n");
 printf(" that passes through these three XY. \n\n");
 printf(" x y");
 p_mR(XY,S5,P0,C6);
 printf("\n");
 printf(" Using the given XY, we obtain this matrix.\n");
 printf(" (a = 1. This is my choice)\n\n");
 printf(" x**2 y**2 x y ");
 p_mR(Ab,S7,P2,C6);
 stop();
 clrscrn();
 QR_uv_mR(A,Q,R); 
 printf(" Q :");
 p_mR(Q,S10,P4,C6); 
 printf(" R :");
 p_mR(R,S10,P4,C6);
 stop();
 clrscrn();
 transpose_mR(Q,Q_T); 
 printf(" Q_T :");
 pE_mR(Q_T,S12,P4,C6); 
 inv_mR(R,invR); 
 printf(" invR :");
 pE_mR(invR,S12,P4,C6);
 stop();
 clrscrn();
 printf(" Solving this system yields a unique\n"
 " least squares solution, namely \n\n");
 mul_mR(invR,Q_T,invR_Q_T);
 mul_mR(invR_Q_T,b,x);
 printf(" x = invR * Q_T * b :");
 p_mR(x,S10,P2,C6);
 printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
 " %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\n\n"
 ,x[R1][C1],x[R2][C1],x[R3][C1],x[R4][C1],x[R5][C1]); 
 stop();
 f_mR(XY); 
 f_mR(A);
 f_mR(b);
 f_mR(Ab);
 f_mR(Q);
 f_mR(Q_T);
 f_mR(R);
 f_mR(invR); 
 f_mR(invR_Q_T); 
 f_mR(x); 
/* ------------------------------------ */
int main(void)

fun();
 return 0;
/* ------------------------------------ */
 Calculons les coefficients a, b, c, d d'un cercle,
 ax**2 + ay**2 + bx + cy + d = 0 
 Qui passe par ces trois points. 
 (x[1],y[1]) (x[2],y[2]) (x[3],y[3]) 
 En utilisant ces trois points nous avons cette matrice.
 (a)x**2 (a)y**2 (b)x (c)y (d) = 0 
 x[1]**2 y[1]**2 x[1] y[1] 1 0
 x[2]**2 y[2]**2 x[2] y[2] 1 0
 x[3]**2 y[3]**2 x[3] y[3] 1 0
 Ce système a trois lignes et quatre inconnues.
 Il est homogène, donc il a une infinité de solution.
 Pour trouver une solution j'ai choisi que a = 1.
 Nous obtenons cette matrice.
 (a)x**2 (a)y**2 
 1 0 0 0 0 1 
 0 1 0 0 0 1 
 x[1]**2 y[1]**2 x[1] y[1] 1 0 
 x[2]**2 y[2]**2 x[2] y[2] 1 0 
 x[3]**2 y[3]**2 x[3] y[3] 1 0 
 Il suffit de resoudre le système.