Mathc matrices/c21j
Sommaire ◀ Utilise la commande "Retour en Arrière" de ton navigateur.
Installer et compiler ces fichiers dans votre répertoire de travail.
c01b.c |
---|
/* ------------------------------------ */
/* Save as : c01b.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R5
#define CA C2
/* ------------------------------------ */
#define FACTOR_E +1.E-0
/* ------------------------------------ */
void fun(void)
{
double tA[RA*CA]={
/* x**0 x**1 */
1, 5.1,
1, 5.3,
1, 5.5,
1, 5.7,
1, 6.0
};
double tb[RA*C1]={
/* y */
0.19,
0.32,
1.04,
2.47,
3.74
};
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,S5,P1,C7);
printf(" b :");
p_mR(b,S5,P1,C7);
printf(" Pinv = V * invS_T * U_T ");
pseudo_Rn_mR(A,Pinv,FACTOR_E);
pE_mR(Pinv,S12,P4,C10);
stop();
clrscrn();
printf(" Solving this system yields a unique\n"
" least squares solution, namely \n\n");
printf(" x = Pinv * b ");
mul_mR(Pinv,b,Pinvb);
p_mR(Pinvb,S10,P4,C10);
printf(" The linear Curve to Data : \n\n"
" s = %+.2f %+.2f*t \n\n"
,Pinvb[R1][C1],Pinvb[R2][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.0 +5.1
+1.0 +5.3
+1.0 +5.5
+1.0 +5.7
+1.0 +6.0
b :
+0.2
+0.3
+1.0
+2.5
+3.7
Pinv = V * invS_T * U_T
+4.9508 +2.6885 +0.4262 -1.8361 -5.2295
-0.8607 -0.4508 -0.0410 +0.3689 +0.9836
Press return to continue.
-----------------------------------
Solving this system yields a unique
least squares solution, namely
x = Pinv * b
-21.8492
+4.2393
The linear Curve to Data :
s = -21.85 +4.24*t
Press return to continue.