Mathc matrices/c23i
Apparence
Sommaire ◀ Utilise la commande "Retour en Arrière" de ton navigateur.
Installer et compiler ces fichiers dans votre répertoire de travail.
c00j.c |
---|
/* ------------------------------------ */
/* Save as : c00j.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R4
#define CA C4
#define Cb C1
/* ------------------------------------ */
/* ------------------------------------ */
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.