Mathc matrices/c23l
Application ou QR décomposition 
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c00m.c */
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
double xy[8] ={
 1, 0,
 2, 3,
 3, 4,
 4, 0 };
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, +0.00, +1.00, +0.00, +1.00, +0.00, 
 +4.00, +9.00, +2.00, +3.00, +1.00, +0.00, 
 +9.00, +16.00, +3.00, +4.00, +1.00, +0.00, 
 +16.00, +0.00, +4.00, +0.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 **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, 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();
 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;
/* ------------------------------------ */
 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. 
 On utilise la QR décomposition. Dans l'exemple suivant on utilise un autre algorithme sur le même exemple.

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 +0 
 +2 +3 
 +3 +4 
 +4 +0 
 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 +0.00 +1.00 +0.00 +1.00 +0.00 
 +4.00 +9.00 +2.00 +3.00 +1.00 +0.00 
 +9.00 +16.00 +3.00 +4.00 +1.00 +0.00 
 +16.00 +0.00 +4.00 +0.00 +1.00 +0.00 
 Press return to continue. 
 -----------------------------------
 Q :
 +0.0531 -0.0323 -0.2668 +0.1748 +0.9457 
 +0.0531 -0.0323 +0.7999 -0.5069 +0.3152 
 +0.2123 +0.4447 +0.4686 +0.7332 -0.0000 
 +0.4777 +0.7296 -0.2636 -0.4124 +0.0000 
 +0.8492 -0.5175 -0.0022 +0.0694 -0.0788 
 R :
 +18.8414 +9.5534 +5.3074 +2.5476 +1.5922 
 +0.0000 +15.6759 +0.9758 +4.2525 +0.6244 
 -0.0000 -0.0000 +0.9375 +0.3514 +1.0027 
 +0.0000 -0.0000 +0.0000 +0.5499 -0.1167 
 +0.0000 +0.0000 +0.0000 +0.0000 +0.2364 
 Press return to continue. 
 -----------------------------------
 Q_T :
 +5.3074e-02 +5.3074e-02 +2.1230e-01 +4.7767e-01 +8.4919e-01 
 -3.2345e-02 -3.2345e-02 +4.4475e-01 +7.2957e-01 -5.1753e-01 
 -2.6681e-01 +7.9987e-01 +4.6856e-01 -2.6357e-01 -2.2010e-03 
 +1.7476e-01 -5.0692e-01 +7.3320e-01 -4.1242e-01 +6.9449e-02 
 +9.4573e-01 +3.1524e-01 -8.6284e-15 +7.0729e-15 -7.8811e-02 
 invR :
 +5.3074e-02 -3.2345e-02 -2.6681e-01 +1.7476e-01 +9.4573e-01 
 +0.0000e+00 +6.3792e-02 -6.6396e-02 -4.5089e-01 -1.0946e-01 
 +0.0000e+00 +0.0000e+00 +1.0667e+00 -6.8168e-01 -4.8600e+00 
 -0.0000e+00 -0.0000e+00 -0.0000e+00 +1.8185e+00 +8.9757e-01 
 -0.0000e+00 -0.0000e+00 -0.0000e+00 -0.0000e+00 +4.2295e+00 
 Press return to continue. 
 -----------------------------------
 Solving this system yields a unique
 least squares solution, namely 
 x = invR * Q_T * b :
 +1.00 
 -0.17 
 -5.00 
 +1.17 
 +4.00 
 The coefficients a, b, c, d, e, of the curve are : 
 +1.00x**2 -0.17y**2 -5.00x +1.17y +4.00 = 0
 Press return to continue.

Mathc matrices/c23m
Application ou Résoudre avec ... 
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c00n.c */
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
double xy[8] ={
 1, 0,
 2, 3,
 3, 4,
 4, 0 };
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, +0.00, +1.00, +0.00, +1.00, +0.00, 
 +4.00, +9.00, +2.00, +3.00, +1.00, +0.00, 
 +9.00, +16.00, +3.00, +4.00, +1.00, +0.00, 
 +16.00, +0.00, +4.00, +0.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**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(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)