Mathc complexes/07w
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
#define RXY R4
#define CXY C2
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double xy[RXY*CXY] ={
-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(RA,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 **A_T = i_mZ(CA,RA);
double **A_TA = i_mZ(CA,CA); // A_T*A
double **invA_TA = i_mZ(CA,CA); // inv(A_T*A)
double **invA_TAA_T = i_mZ(CA,RA); // inv(A_T*A)*A_T
double **x = i_mZ(CA,Cb); // x = inv(A_T*A)*A_T*b
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c 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 points, we obtain this matrix.\n");
printf(" x**3 x**2 x**1 x**0 y\n");
p_mRZ(Ab,S7,P2,C6);
stop();
clrscrn();
printf(" A_T :");
p_mRZ(transpose_mZ(A,A_T),S10,P2,C7);
printf(" A_TA :");
p_mRZ(mul_mZ(A_T,A,A_TA),S10,P2,C7);
stop();
clrscrn();
printf(" inv(A_TA) :");
p_mRZ(inv_mZ(A_TA,invA_TA),S10,P4,C7);
printf(" inv(A_TA)*A_T :");
p_mRZ(mul_mZ(invA_TA,A_T,invA_TAA_T),S10,P4,C7);
printf("\n x = inv(A_TA)*A_T*b :");
p_mRZ(mul_mZ(invA_TAA_T,b,x),S10,P4,C7);
stop();
clrscrn();
printf("\n x = inv(A_TA)*A_T*b :");
p_mRZ(x,S10,P2,C7);
printf("\n The coefficients a, b, c of the curve are : \n\n"
" y = %+.2fx**3 %+.2fx \n\n"
,x[R1][C1],x[R3][C1]);
stop();
f_mZ(XY);
f_mZ(A);
f_mZ(b);
f_mZ(Ab);
f_mZ(A_T);
f_mZ(A_TA); // A_T*A
f_mZ(invA_TA); // inv(A_T*A)
f_mZ(invA_TAA_T); // inv(A_T*A)*A_T
f_mZ(x);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Exemple de sortie écran :
Find the coefficients a, b, c 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 points, 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.
A_T :
-125.00 -8.00 +8.00 +125.00
+25.00 +4.00 +4.00 +25.00
-5.00 -2.00 +2.00 +5.00
+1.00 +1.00 +1.00 +1.00
A_TA :
+31378.00 +0.00 +1282.00 +0.00
+0.00 +1282.00 +0.00 +58.00
+1282.00 +0.00 +58.00 +0.00
+0.00 +58.00 +0.00 +4.00
Press return to continue.
inv(A_TA) :
+0.0003 -0.0000 -0.0073 +0.0000
-0.0000 +0.0023 +0.0000 -0.0329
-0.0073 +0.0000 +0.1779 -0.0000
+0.0000 -0.0329 -0.0000 +0.7268
inv(A_TA)*A_T :
-0.0048 +0.0119 -0.0119 +0.0048
+0.0238 -0.0238 -0.0238 +0.0238
+0.0190 -0.2976 +0.2976 -0.0190
-0.0952 +0.5952 +0.5952 -0.0952
x = inv(A_TA)*A_T*b :
+0.2667
+0.0000
-5.0667
+0.0000
Press return to continue.
x = inv(A_TA)*A_T*b :
+0.27
+0.00
-5.07
+0.00
The coefficients a, b, c of the curve are :
y = +0.27x**3 -5.07x
Press return to continue.