Mathc matrices/c05m
Sommaire ◀ Utilise la commande "Retour en Arrière" de ton navigateur.
Installer et compiler ces fichiers dans votre répertoire de travail.
c01e.c |
---|
/* ------------------------------------ */
/* Save as : c01e.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R5
#define CA C5
/* ------------------------------------ */
#define FACTOR_E +1.E-2
/* ------------------------------------ */
void fun(void)
{
double tA[RA*CA]={
/* x**0 x**1 x**2 x**3 x**4 */
1, 1., 1., 1., 1.,
1, 2., 4., 8., 16.,
1, 3., 9., 27., 81.,
1, 4., 16., 64., 256.,
1, 5., 25., 125., 625.
};
double tb[RA*C1]={
/* y */
-5.,
8.,
-7.,
1.,
-4.
};
double **A = ca_A_mR(tA,i_mR(RA,CA));
double **b = ca_A_mR(tb,i_mR(RA,C1));
double **Pinv = i_mR(CA,RA);
double **Pinvb = i_mR(CA,C1);
clrscrn();
printf(" Fitting a linear Curve to Data :\n\n");
printf(" A :");
p_mR(A,S10,P2,C7);
printf(" b :");
p_mR(b,S10,P2,C7);
printf(" Pinv = V * invS_T * U_T ");
Pinv_Rn_mR(A,Pinv,FACTOR_E);
pE_mR(Pinv,S12,P4,C10);
printf(" x = Pinv * b ");
mul_mR(Pinv,b,Pinvb);
p_mR(Pinvb,S10,P4,C10);
printf(" The Quartic equation Curve to Data : \n\n"
" s = %+.3f %+.3f*t %+.3f*t**2 %+.3f*t**3 %+.3f*t**4\n\n"
,Pinvb[R1][C1],Pinvb[R2][C1],Pinvb[R3][C1],
Pinvb[R4][C1],Pinvb[R5][C1]);
stop();
f_mR(b);
f_mR(A);
f_mR(Pinv);
f_mR(Pinvb);
}
/* ------------------------------------ */
int main(void)
{
fun();
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Exemple de sortie écran :
-----------------------------------
Fitting a linear 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
Press return to continue.
-----------------------------------
Pinv = V * invS_T * U_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 = Pinv * b
-183.9999
+329.7500
-191.8750
+44.7500
-3.6250
The Quartic equation Curve to Data :
s = -184.000 +329.750*t -191.875*t**2 +44.750*t**3 -3.625*t**4