Mathc matrices/c23j
Application ou QR décomposition 
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c00k.c */
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
double ab[RA*(CA+Cb)]={
/* x**0 x**1 x**2 x**3 x**4 y */
 1, 1., 1., 1., 1., -5.,
 1, 2., 4., 8., 16., 8.,
 1, 3., 9., 27., 81., -7.,
 1, 4., 16., 64., 256., 1.,
 1, 5., 25., 125., 625., -4.,
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 quartic 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 Quartic equation Curve to Data : \n\n"
 " s = %+.3f %+.3f*t %+.3f*t**2 %+.3f*t**3 %+.3f*t**4\n\n"
 ,x[R1][C1],x[R2][C1],x[R3][C1],x[R4][C1],x[R5][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 quartique 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 quartic equation Curve to Data :
 A :
 +1.00 +1.00 +1.00 +1.00 +1.00 
 +1.00 +2.00 +4.00 +8.00 +16.00 
 +1.00 +3.00 +9.00 +27.00 +81.00 
 +1.00 +4.00 +16.00 +64.00 +256.00 
 +1.00 +5.00 +25.00 +125.00 +625.00 
 b :
 -5.00 
 +8.00 
 -7.00 
 +1.00 
 -4.00 
 Ab :
 +1.00 +1.00 +1.00 +1.00 +1.00 -5.00 
 +1.00 +2.00 +4.00 +8.00 +16.00 +8.00 
 +1.00 +3.00 +9.00 +27.00 +81.00 -7.00 
 +1.00 +4.00 +16.00 +64.00 +256.00 +1.00 
 +1.00 +5.00 +25.00 +125.00 +625.00 -4.00 
 Press return to continue. 
 -----------------------------------
 Q :
 +0.4472 -0.6325 +0.5345 -0.3162 +0.1195 
 +0.4472 -0.3162 -0.2673 +0.6325 -0.4781 
 +0.4472 +0.0000 -0.5345 +0.0000 +0.7171 
 +0.4472 +0.3162 -0.2673 -0.6325 -0.4781 
 +0.4472 +0.6325 +0.5345 +0.3162 +0.1195 
 R :
 +2.2361 +6.7082 +24.5967 +100.6231 +437.8221 
 +0.0000 +3.1623 +18.9737 +96.1332 +470.5469 
 +0.0000 +0.0000 +3.7417 +33.6749 +218.6197 
 +0.0000 +0.0000 +0.0000 +3.7947 +45.5368 
 -0.0000 -0.0000 -0.0000 -0.0000 +2.8685 
 Press return to continue. 
 -----------------------------------
 Q_T :
+4.4721e-01 +4.4721e-01 +4.4721e-01 +4.4721e-01 +4.4721e-01 
-6.3246e-01 -3.1623e-01 +0.0000e+00 +3.1623e-01 +6.3246e-01 
+5.3452e-01 -2.6726e-01 -5.3452e-01 -2.6726e-01 +5.3452e-01 
-3.1623e-01 +6.3246e-01 +0.0000e+00 -6.3246e-01 +3.1623e-01 
+1.1952e-01 -4.7809e-01 +7.1714e-01 -4.7809e-01 +1.1952e-01 
 invR :
+4.4721e-01 -9.4868e-01 +1.8708e+00 -4.4272e+00 +1.5060e+01 
+0.0000e+00 +3.1623e-01 -1.6036e+00 +6.2191e+00 -2.8387e+01 
-0.0000e+00 +0.0000e+00 +2.6726e-01 -2.3717e+00 +1.7281e+01 
+0.0000e+00 -0.0000e+00 +0.0000e+00 +2.6352e-01 -4.1833e+00 
-0.0000e+00 +0.0000e+00 -0.0000e+00 -0.0000e+00 +3.4861e-01 
 Press return to continue. 
 -----------------------------------
 Solving this system yields a unique
 least squares solution, namely 
 x = invR * Q_T * b :
 -184.00 
 +329.75 
 -191.87 
 +44.75 
 -3.63 
 The Quartic equation Curve to Data : 
 s = -184.000 +329.750*t -191.875*t**2 +44.750*t**3 -3.625*t**4
 Press return to continue.

Mathc matrices/c23k
Application ou Résoudre avec ... 
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c00l.c */
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
double ab[RA*(CA+Cb)]={
/* x**0 x**1 x**2 x**3 x**4 y */
 1, 1., 1., 1., 1., -5.,
 1, 2., 4., 8., 16., 8.,
 1, 3., 9., 27., 81., -7.,
 1, 4., 16., 64., 256., 1.,
 1, 5., 25., 125., 625., -4.,
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 Quartic equation Curve to Data :\n\n");
 printf(" A :");
 p_mR(A,S10,P2,C7);
 printf(" b :");
 p_mR(b,S10,P2,C7);
 printf(" Ab :");
 p_mR(Ab,S10,P2,C7);
 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);
 printf(" inv(A_TA) :");
 p_mR(inv_mR(A_TA,invA_TA),S10,P4,C7);
 stop();
 clrscrn(); 
 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 Quartic equation Curve to Data : \n\n"
 " s = %+.3f %+.3f*t %+.3f*t**2 %+.3f*t**3 %+.3f*t**4\n\n"
 ,x[R1][C1],x[R2][C1],x[R3][C1],x[R4][C1],x[R5][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)

Exemple de sortie écran :
 Fitting a Quartic equation Curve to Data :
 A :
 +1.00 +1.00 +1.00 +1.00 +1.00 
 +1.00 +2.00 +4.00 +8.00 +16.00 
 +1.00 +3.00 +9.00 +27.00 +81.00 
 +1.00 +4.00 +16.00 +64.00 +256.00 
 +1.00 +5.00 +25.00 +125.00 +625.00 
 b :
 -5.00 
 +8.00 
 -7.00 
 +1.00 
 -4.00 
 Ab :
 +1.00 +1.00 +1.00 +1.00 +1.00 -5.00 
 +1.00 +2.00 +4.00 +8.00 +16.00 +8.00 
 +1.00 +3.00 +9.00 +27.00 +81.00 -7.00 
 +1.00 +4.00 +16.00 +64.00 +256.00 +1.00 
 +1.00 +5.00 +25.00 +125.00 +625.00 -4.00 
 Press return to continue. 
 -----------------------------------
 A_T :
 +1.00 +1.00 +1.00 +1.00 +1.00 
 +1.00 +2.00 +3.00 +4.00 +5.00 
 +1.00 +4.00 +9.00 +16.00 +25.00 
 +1.00 +8.00 +27.00 +64.00 +125.00 
 +1.00 +16.00 +81.00 +256.00 +625.00 
 A_TA :
 +5.00 +15.00 +55.00 +225.00 +979.00 
 +15.00 +55.00 +225.00 +979.00 +4425.00 
 +55.00 +225.00 +979.00 +4425.00 +20515.00 
 +225.00 +979.00 +4425.00 +20515.00 +96825.00 
 +979.00 +4425.00 +20515.00 +96825.00 +462979.00 
 inv(A_TA) :
 +251.0000 -458.3333 +271.2500 -64.1667 +5.2500 
 -458.3333 +847.1528 -505.7292 +120.3889 -9.8958 
 +271.2500 -505.7292 +304.3299 -72.9167 +6.0243 
 -64.1667 +120.3889 -72.9167 +17.5694 -1.4583 
 +5.2500 -9.8958 +6.0243 -1.4583 +0.1215 
 Press return to continue. 
 -----------------------------------
 inv(A_TA)*A_T :
 +5.0000 -10.0000 +10.0000 -5.0000 +1.0000 
 -6.4167 +17.8333 -19.5000 +10.1667 -2.0833 
 +2.9583 -9.8333 +12.2500 -6.8333 +1.4583 
 -0.5833 +2.1667 -3.0000 +1.8333 -0.4167 
 +0.0417 -0.1667 +0.2500 -0.1667 +0.0417 
 x = inv(A_TA)*A_T*b :
 -184.0000 
 +329.7500 
 -191.8750 
 +44.7500 
 -3.6250 
 Press return to continue. 
 x = inv(A_TA)*A_T*b :
 -184.00 
 +329.75 
 -191.88 
 +44.75 
 -3.63 
 The Quartic equation Curve to Data : 
 s = -184.000 +329.750*t -191.875*t**2 +44.750*t**3 -3.625*t**4