Mathc matrices/c22z
Application ou QR décomposition
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c00i.c */
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
double ab[RA*(CA+Cb)]={
/* x**0 x**1 x**2 x**3 y */
 1, -5., +25., -125., -3.00,
 1, -2., +4., -8., +0.00,
 1, +2., +4., +8., +3.00,
 1, +3., +9., +27., -2.00,
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(" Fitting a Cubic equation Curve to Data :\n\n");
 printf(" A :");
 p_mR(A,S7,P2,C7);
 printf(" b :");
 p_mR(b,S7,P2,C7);
 printf(" Ab :");
 p_mR(Ab,S7,P2,C7);
 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,S7,P4,C6); 
 inv_mR(R,invR); 
 printf(" invR :");
 pE_mR(invR,S7,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 Cubic equation Curve to Data : \n\n"
 " s = %+.3f %+.3f*t %+.3f*t**2 %+.3f*t**2\n\n"
 ,x[R1][C1],x[R2][C1],x[R3][C1],x[R4][C1]); 
 stop();
 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 la meilleur équation cubique qui s'ajuste au mieux aux points donnés.
 On utilise la QR décomposition. Dans l'exemple suivant on utilise un autre algorithme sur le même exemple.

Exemple de sortie écran :
 Fitting a Cubic equation Curve to Data :
 A :
 +1.00 -5.00 +25.00 -125.00 
 +1.00 -2.00 +4.00 -8.00 
 +1.00 +2.00 +4.00 +8.00 
 +1.00 +3.00 +9.00 +27.00 
 b :
 -3.00 
 +0.00 
 +3.00 
 -2.00 
 Ab :
 +1.00 -5.00 +25.00 -125.00 -3.00 
 +1.00 -2.00 +4.00 -8.00 +0.00 
 +1.00 +2.00 +4.00 +8.00 +3.00 
 +1.00 +3.00 +9.00 +27.00 -2.00 
 Press return to continue. 
 -----------------------------------
 Q :
 +0.5000 -0.7028 +0.4900 -0.1265 
 +0.5000 -0.2343 -0.7547 +0.3542 
 +0.5000 +0.3904 -0.1462 -0.7591 
 +0.5000 +0.5466 +0.4110 +0.5313 
 R :
 +2.0000 -1.0000 +21.0000 -49.0000 
 +0.0000 +6.4031 -12.0254 +107.6037 
 +0.0000 -0.0000 +12.3446 -45.2848 
 -0.0000 -0.0000 +0.0000 +21.2539 
 Press return to continue. 
 -----------------------------------
 Q_T :
+5.0000e-01 +5.0000e-01 +5.0000e-01 +5.0000e-01 
-7.0278e-01 -2.3426e-01 +3.9043e-01 +5.4661e-01 
+4.8999e-01 -7.5475e-01 -1.4621e-01 +4.1096e-01 
-1.2651e-01 +3.5423e-01 -7.5907e-01 +5.3135e-01 
 invR :
+5.0000e-01 +7.8087e-02 -7.7450e-01 -8.9281e-01 
+0.0000e+00 +1.5617e-01 +1.5213e-01 -4.6653e-01 
-0.0000e+00 -0.0000e+00 +8.1007e-02 +1.7260e-01 
-0.0000e+00 -0.0000e+00 +0.0000e+00 +4.7050e-02 
 Press return to continue. 
 -----------------------------------
 Solving this system yields a unique
 least squares solution, namely 
 x = invR * Q_T * b :
 +4.43 
 +1.31 
 -0.73 
 -0.14 
 The Cubic equation Curve to Data : 
 s = +4.429 +1.307*t -0.732*t**2 -0.139*t**2
 Press return to continue.

Mathc matrices/c23i
Application ou Résoudre avec ...
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c00j.c */
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
double ab[RA*(CA+Cb)]={
/* x**0 x**1 x**2 x**3 y */
 1, -5., +25., -125., -3.00 ,
 1, -2., +4., -8., +0.00,
 1, +2., +4., +8., +3.00,
 1, +3., +9., +27., -2.00,
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(" Fitting a Cubic equation Curve to Data :\n\n");
 printf(" A :");
 p_mR(A,S7,P2,C7);
 printf(" b :");
 p_mR(b,S7,P2,C7);
 printf(" Ab :");
 p_mR(Ab,S7,P2,C7);
 stop();
 clrscrn();
 printf(" A_T :");
 p_mR(transpose_mR(A,A_T),S7,P2,C7);
 printf(" A_TA :");
 p_mR(mul_mR(A_T,A,A_TA),S7,P2,C7);
 printf(" inv(A_TA) :");
 p_mR(inv_mR(A_TA,invA_TA),S7,P4,C7);
 stop();
 clrscrn(); 
 printf(" inv(A_TA)*A_T :");
 p_mR(mul_mR(invA_TA,A_T,invA_TAA_T),S7,P4,C7);
 printf("\n x = inv(A_TA)*A_T*b :");
 p_mR(mul_mR(invA_TAA_T,b,x),S7,P4,C7);
 stop();
 clrscrn();
 printf("\n x = inv(A_TA)*A_T*b :");
 p_mR(x,S7,P2,C7); 
 printf(" The Cubic equation Curve to Data : \n\n"
 " s = %+.3f %+.3f*t %+.3f*t**2 %+.3f*t**3\n\n"
 ,x[R1][C1],x[R2][C1],x[R3][C1],x[R4][C1]); 
 stop(); 
 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 la meilleur équation cubique qui s'ajuste au mieux aux points donnés.

Exemple de sortie écran :
 Fitting a Cubic equation Curve to Data :
 A :
 +1.00 -5.00 +25.00 -125.00 
 +1.00 -2.00 +4.00 -8.00 
 +1.00 +2.00 +4.00 +8.00 
 +1.00 +3.00 +9.00 +27.00 
 b :
 -3.00 
 +0.00 
 +3.00 
 -2.00 
 Ab :
 +1.00 -5.00 +25.00 -125.00 -3.00 
 +1.00 -2.00 +4.00 -8.00 +0.00 
 +1.00 +2.00 +4.00 +8.00 +3.00 
 +1.00 +3.00 +9.00 +27.00 -2.00 
 Press return to continue. 
 -----------------------------------
 A_T :
 +1.00 +1.00 +1.00 +1.00 
 -5.00 -2.00 +2.00 +3.00 
 +25.00 +4.00 +4.00 +9.00 
-125.00 -8.00 +8.00 +27.00 
 A_TA :
 +4.00 -2.00 +42.00 -98.00 
 -2.00 +42.00 -98.00 +738.00 
 +42.00 -98.00 +738.00 -2882.00 
 -98.00 +738.00 -2882.00 +16482.00 
 inv(A_TA) :
+1.6531 +0.3109 -0.2168 -0.0420 
+0.3109 +0.2652 -0.0682 -0.0220 
-0.2168 -0.0682 +0.0364 +0.0081 
-0.0420 -0.0220 +0.0081 +0.0022 
 Press return to continue. 
 -----------------------------------
 inv(A_TA)*A_T :
-0.0714 +0.5000 +1.0714 -0.5000 
+0.0238 -0.3167 +0.3929 -0.1000 
+0.0179 -0.0000 -0.1429 +0.1250 
-0.0060 +0.0167 -0.0357 +0.0250 
 x = inv(A_TA)*A_T*b :
+4.4286 
+1.3071 
-0.7321 
-0.1393 
 Press return to continue. 
 -----------------------------------
 x = inv(A_TA)*A_T*b :
 +4.43 
 +1.31 
 -0.73 
 -0.14 
 The Cubic equation Curve to Data : 
 s = +4.429 +1.307*t -0.732*t**2 -0.139*t**3
 Press return to continue.