Mathc complexes/06z
Apparence
Installer et compiler ces fichiers dans votre répertoire de travail.
c00d.c |
|---|
/* ------------------------------------ */
/* Save as : c00d.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R4
#define CA C4
#define Cb C1
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double xy[8] ={ -5, -8,
-2, 8,
2, -8,
5, 8 };
double ab[RA*(CA+Cb)]={
/* x**3 x**2 x**1 x**0 y */
-125, +25, -5, +1, -8,
-8, +4, -2, +1, +8,
+8, +4, +2, +1, -8,
+125, +25, +5, +1, +8,
};
double **XY = ca_A_mRZ(xy,i_mZ(R4,C2));
double **Ab = ca_A_mRZ(ab,i_Abr_Ac_bc_mZ(RA,CA,Cb));
double **A = c_Ab_A_mZ(Ab,i_mZ(RA,CA));
double **b = c_Ab_b_mZ(Ab,i_mZ(RA,Cb));
double **Q = i_mZ(RA,CA);
double **R = i_mZ(CA,CA);
double **invR = i_mZ(CA,CA);
double **Q_T = i_mZ(CA,RA);
double **invR_Q_T = i_mZ(CA,RA);
double **x = i_mZ(CA,Cb); // x invR * Q_T * b
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c, d of the curve \n\n");
printf(" y = ax**3 + bx**2 + cx + d \n\n");
printf(" that passes through the points. \n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
printf("\n");
printf(" Using the given XY, we obtain this matrix.\n");
printf(" x**3 x**2 x**1 x**0 y\n");
p_mRZ(Ab,S7,P2,C6);
stop();
clrscrn();
QR_mZ(A,Q,R);
printf(" Q :");
p_mRZ(Q,S10,P4,C6);
printf(" R :");
p_mRZ(R,S10,P4,C6);
stop();
clrscrn();
transpose_mZ(Q,Q_T);
printf(" Q_T :");
pE_mRZ(Q_T,S12,P4,C6);
inv_mZ(R,invR);
printf(" invR :");
pE_mRZ(invR,S12,P4,C6);
stop();
clrscrn();
printf(" Solving this system yields a unique\n"
" least squares solution, namely \n\n");
mul_mZ(invR,Q_T,invR_Q_T);
mul_mZ(invR_Q_T,b,x);
printf(" x = invR * Q_T * b :");
p_mRZ(x,S10,P3,C6);
printf(" The coefficients a, b, c, d of the curve are : \n\n"
" y = %+.3fx**3 %+.3fx \n\n"
,x[R1][C1],x[R3][C1]);
stop();
f_mZ(XY);
f_mZ(A);
f_mZ(b);
f_mZ(Ab);
f_mZ(Q);
f_mZ(Q_T);
f_mZ(R);
f_mZ(invR);
f_mZ(invR_Q_T);
f_mZ(x);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Exemple de sortie écran :
Find the coefficients a, b, c, d of the curve
y = ax**3 + bx**2 + cx + d
that passes through the points.
x y
-5 -8
-2 +8
+2 -8
+5 +8
Using the given XY, we obtain this matrix.
x**3 x**2 x**1 x**0 y
-125.00 +25.00 -5.00 +1.00 -8.00
-8.00 +4.00 -2.00 +1.00 +8.00
+8.00 +4.00 +2.00 +1.00 -8.00
+125.00 +25.00 +5.00 +1.00 +8.00
Press return to continue.
Q :
-0.7057 +0.6982 +0.0452 -0.1117
-0.0452 +0.1117 -0.7057 +0.6982
+0.0452 +0.1117 +0.7057 +0.6982
+0.7057 +0.6982 -0.0452 -0.1117
R :
+177.1384 +0.0000 +7.2373 +0.0000
+0.0000 +35.8050 +0.0000 +1.6199
-0.0000 +0.0000 +2.3710 +0.0000
-0.0000 +0.0000 +0.0000 +1.1730
Press return to continue.
Q_T :
-7.0566e-01 -4.5162e-02 +4.5162e-02 +7.0566e-01
+6.9823e-01 +1.1172e-01 +1.1172e-01 +6.9823e-01
+4.5162e-02 -7.0566e-01 +7.0566e-01 -4.5162e-02
-1.1172e-01 +6.9823e-01 +6.9823e-01 -1.1172e-01
invR :
+5.6453e-03 +0.0000e+00 -1.7232e-02 +0.0000e+00
+0.0000e+00 +2.7929e-02 +0.0000e+00 -3.8569e-02
+0.0000e+00 -0.0000e+00 +4.2176e-01 -0.0000e+00
-0.0000e+00 +0.0000e+00 -0.0000e+00 +8.5250e-01
Press return to continue.
Solving this system yields a unique
least squares solution, namely
x = invR * Q_T * b :
+0.267
+0.000
-5.067
+0.000
The coefficients a, b, c, d of the curve are :
y = +0.267x**3 -5.067x
Press return to continue.