Mathc matrices/c22y
Apparence
Sommaire ◀ Utilise la commande "Retour en Arrière" de ton navigateur.
Installer et compiler ces fichiers dans votre répertoire de travail.
c00h.c |
---|
/* ------------------------------------ */
/* Save as : c00h.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R5
#define CA C2
#define Cb C1
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
{
double ab[RA*(CA+Cb)]={
/* x**0 x**1 y */
1, 5.1, 0.19,
1, 5.3, 0.32,
1, 5.5, 1.04,
1, 5.7, 2.47,
1, 6.0, 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 linear 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 linear Curve to Data : \n\n:"
" s = %+.2f %+.2f*t \n\n"
,x[R1][C1],x[R2][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 linéaire qui s'ajuste au mieux aux points donnés
Exemple de sortie écran :
-----------------------------------
Fitting a linear Curve to Data :
A :
+1.00 +5.10
+1.00 +5.30
+1.00 +5.50
+1.00 +5.70
+1.00 +6.00
b :
+0.19
+0.32
+1.04
+2.47
+3.74
Ab :
+1.00 +5.10 +0.19
+1.00 +5.30 +0.32
+1.00 +5.50 +1.04
+1.00 +5.70 +2.47
+1.00 +6.00 +3.74
Press return to continue.
-----------------------------------
A_T :
+1.00 +1.00 +1.00 +1.00 +1.00
+5.10 +5.30 +5.50 +5.70 +6.00
A_TA :
+5.00 +27.60
+27.60 +152.84
inv(A_TA) :
+62.6393 -11.3115
-11.3115 +2.0492
inv(A_TA)*A_T :
+4.9508 +2.6885 +0.4262 -1.8361 -5.2295
-0.8607 -0.4508 -0.0410 +0.3689 +0.9836
x = inv(A_TA)*A_T*b :
-21.8492
+4.2393
Press return to continue.
-----------------------------------
x = inv(A_TA)*A_T*b :
-21.85
+4.24
The linear Curve to Data :
s = -21.85 +4.24*t
Press return to continue.