fun();
 return 0;
/* ------------------------------------ */
 Le nombre de lignes doit être supérieurs aux nombres de colonnes. La fonction gaussjordan ne fonctionne pas dans cette situation.
 On utilise la QR décomposition. Dans l'exemple suivant on utilise un autre algorithme sur le même exemple.

Exemple de sortie écran :
Unique Least Squares Solution :
 A :
 +1.0 -1.0 
 +3.0 +2.0 
 -2.0 +4.0 
 b :
 +4.0 
 +1.0 
 +3.0 
 Ab :
 +1.0 -1.0 +4.0 
 +3.0 +2.0 +1.0 
 -2.0 +4.0 +3.0 
 Press return to continue. 
 -----------------------------------
 Q :
+0.2673 -0.1741 
+0.8018 +0.5858 
-0.5345 +0.7916 
 R :
 +3.7417 -0.8018 
 -0.0000 +4.5119 
 Press return to continue. 
 Q_T :
+2.6726e-01 +8.0178e-01 -5.3452e-01 
-1.7414e-01 +5.8575e-01 +7.9156e-01 
 invR :
+2.6726e-01 +4.7494e-02 
-0.0000e+00 +2.2164e-01 
 Press return to continue. 
 -----------------------------------
 Solving this system yields a unique
 least squares solution, namely 
 x = invR * Q_T * b :
 +0.1789 
 +0.5018 
 Press return to continue.

Mathc matrices/c22u
Application ou Résoudre avec ...
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c00d.c */
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
double ab[RA*(CA+Cb)]={
 1, -1, 4,
 3, 2, 1,
-2, 4, 3
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("Unique Least Squares Solution :\n\n");
 printf(" A :");
 p_mR(A,S5,P1,C7);
 printf(" b :");
 p_mR(b,S5,P1,C7);
 printf(" Ab :");
 p_mR(Ab,S5,P1,C7);
 stop();
 clrscrn();
 printf(" A_T :");
 p_mR(transpose_mR(A,A_T),S5,P1,C7);
 printf(" A_TA :");
 p_mR(mul_mR(A_T,A,A_TA),S5,P1,C7);
 printf(" inv(A_TA) :");
 p_mR(inv_mR(A_TA,invA_TA),S5,P4,C7); 
 printf(" inv(A_TA)*A_T :");
 p_mR(mul_mR(invA_TA,A_T,invA_TAA_T),S5,P4,C7);
 printf("\n x = inv(A_TA)*A_T*b :");
 p_mR(mul_mR(invA_TAA_T,b,x),S5,P4,C7); 
 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;
/* ------------------------------------ */
 Ici le nombre de lignes doit être supérieurs aux nombres de colonnes. La fonction gaussjordan ne fonctionne pas dans cette situation.

Exemple de sortie écran :
Unique Least Squares Solution :
 A :
 +1.0 -1.0 
 +3.0 +2.0 
 -2.0 +4.0 
 b :
 +4.0 
 +1.0 
 +3.0 
 Ab :
 +1.0 -1.0 +4.0 
 +3.0 +2.0 +1.0 
 -2.0 +4.0 +3.0 
 Press return to continue. 
 A_T :
 +1.0 +3.0 -2.0 
 -1.0 +2.0 +4.0 
 A_TA :
+14.0 -3.0 
 -3.0 +21.0 
 inv(A_TA) :
+0.0737 +0.0105 
+0.0105 +0.0491 
 inv(A_TA)*A_T :
+0.0632 +0.2421 -0.1053 
-0.0386 +0.1298 +0.1754 
 x = inv(A_TA)*A_T*b :
+0.1789 
+0.5018 
 Press return to continue.

Mathc matrices/c22v
Application ou QR décomposition 
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c00e.c */
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
double ab[RA*(CA+Cb)]={
/* x**0 x**1 x**2 y */
 1, .1, .01, -0.19,
 1, .2, .04, 0.32,
 1, .3, .09, 1.04,
 1, .4, .16, 2.47,
 1, .5, .25, 3.74,
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 Quadratic Curve to Data :\n\n");
 printf(" A :");
 p_mR(A,S5,P2,C7);
 printf(" b :");
 p_mR(b,S5,P2,C7);
 printf(" Ab :");
 p_mR(Ab,S5,P2,C7);
 stop();
 clrscrn();
 QR_uv_mR(A,Q,R); 
 printf(" Q :");
 p_mR(Q,S3,P4,C6); 
 printf(" R :");
 p_mR(R,S10,P4,C6);
 stop();
 clrscrn();
 transpose_mR(Q,Q_T); 
 printf(" Q_T :");
 pE_mR(Q_T,S3,P4,C6); 
 inv_mR(R,invR); 
 printf(" invR :");
 pE_mR(invR,S10,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 Quadratic Curve to Data : \n\n:"
 " s = %+.2f %+.2f*t %+.2f*t**2\n\n"
 ,x[R1][C1],x[R2][C1],x[R3][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 du second degré, 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 Quadratic Curve to Data :
 A :
+1.00 +0.10 +0.01 
+1.00 +0.20 +0.04 
+1.00 +0.30 +0.09 
+1.00 +0.40 +0.16 
+1.00 +0.50 +0.25 
 b :
-0.19 
+0.32 
+1.04 
+2.47 
+3.74 
 Ab :
+1.00 +0.10 +0.01 -0.19 
+1.00 +0.20 +0.04 +0.32 
+1.00 +0.30 +0.09 +1.04 
+1.00 +0.40 +0.16 +2.47 
+1.00 +0.50 +0.25 +3.74 
 Press return to continue. 
 -----------------------------------
 Q :
+0.4472 -0.6325 +0.5345 
+0.4472 -0.3162 -0.2673 
+0.4472 +0.0000 -0.5345 
+0.4472 +0.3162 -0.2673 
+0.4472 +0.6325 +0.5345 
 R :
 +2.2361 +0.6708 +0.2460 
 +0.0000 +0.3162 +0.1897 
 -0.0000 -0.0000 +0.0374 
 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 
 invR :
+4.4721e-01 -9.4868e-01 +1.8708e+00 
+0.0000e+00 +3.1623e+00 -1.6036e+01 
-0.0000e+00 -0.0000e+00 +2.6726e+01 
 Press return to continue. 
 -----------------------------------
 Solving this system yields a unique
 least squares solution, namely 
 x = invR * Q_T * b :
 -0.41 
 +0.45 
 +15.93 
 The Quadratic Curve to Data : 
 s = -0.41 +0.45*t +15.93*t**2

Mathc matrices/c22w
Application ou Résoudre avec ...
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c00f.c */
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
double ab[RA*(CA+Cb)]={
/* x**0 x**1 x**2 y */
 1, .1, .01, -0.19,
 1, .2, .04, 0.32,
 1, .3, .09, 1.04,
 1, .4, .16, 2.47,
 1, .5, .25, 3.74,
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 Quadratic Curve to Data :\n\n");
 printf(" A :");
 p_mR(A,S5,P2,C7);
 printf(" b :");
 p_mR(b,S5,P2,C7);
 printf(" Ab :");
 p_mR(Ab,S5,P2,C7);
 stop();
 clrscrn();
 printf(" A_T :");
 p_mR(transpose_mR(A,A_T),S5,P2,C7);
 printf(" A_TA :");
 p_mR(mul_mR(A_T,A,A_TA),S5,P2,C7);
 printf(" inv(A_TA) :");
 p_mR(inv_mR(A_TA,invA_TA),S5,P4,C7); 
 printf(" inv(A_TA)*A_T :");
 p_mR(mul_mR(invA_TA,A_T,invA_TAA_T),S5,P4,C7);
 printf("\n x = inv(A_TA)*A_T*b :");
 p_mR(mul_mR(invA_TAA_T,b,x),S5,P4,C7);
 stop();
 clrscrn();
 printf("\n x = inv(A_TA)*A_T*b :");
 p_mR(x,S5,P2,C7); 
 printf(" The Quadratic Curve to Data : \n\n:"
 " s = %+.2f %+.2f*t %+.2f*t**2\n\n"
 ,x[R1][C1],x[R2][C1],x[R3][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)