Mathc complexes/07r
Apparence
Installer et compiler ces fichiers dans votre répertoire de travail.
c00d.c |
|---|
/* ------------------------------------ */
/* Save as : c00d.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
#define RXY R4
#define CXY C2
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double xy[R4*(C2*C2)] ={
1, 4,
2, 5,
3, -7,
4, 5 };
double ab[RA*((CA+Cb)*C2)]={
/* x**2 y**2 x y e = +0 */
+1, +0, +0, +0, +0, +1,
+1, +16, +1, +4, +1, +0,
+4, +25, +2, +5, +1, +0,
+9, +49, +3, -7, +1, +0,
+16, +25, +4, +5, +1, +0
};
double **XY = ca_A_mRZ(xy,i_mZ(RXY,CXY));
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, d, e, of the curve \n\n");
printf(" ax**2 + by**2 + cx + dy + e = 0 \n\n");
printf(" that passes through these four 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(" (a = 1. This is my choice)\n\n");
printf(" x**2 y**2 x y ");
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(" The coefficients a, b, c, d, e, of the curve are : \n\n"
" %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\n\n"
,x[R1][C1],x[R2][C1],x[R3][C1],x[R4][C1],x[R5][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, d, e, of the curve
ax**2 + by**2 + cx + dy + e = 0
that passes through these four points.
x y
+1 +4
+2 +5
+3 -7
+4 +5
Using the given XY, we obtain this matrix.
(a = 1. This is my choice)
x**2 y**2 x y
+1.00 +0.00 +0.00 +0.00 +0.00 +1.00
+1.00 +16.00 +1.00 +4.00 +1.00 +0.00
+4.00 +25.00 +2.00 +5.00 +1.00 +0.00
+9.00 +49.00 +3.00 -7.00 +1.00 +0.00
+16.00 +25.00 +4.00 +5.00 +1.00 +0.00
Press return to continue.
A_T :
+1.00 +1.00 +4.00 +9.00 +16.00
+0.00 +16.00 +25.00 +49.00 +25.00
+0.00 +1.00 +2.00 +3.00 +4.00
+0.00 +4.00 +5.00 -7.00 +5.00
+0.00 +1.00 +1.00 +1.00 +1.00
A_TA :
+355.00 +957.00 +100.00 +41.00 +30.00
+957.00 +3907.00 +313.00 -29.00 +115.00
+100.00 +313.00 +30.00 +13.00 +10.00
+41.00 -29.00 +13.00 +115.00 +7.00
+30.00 +115.00 +10.00 +7.00 +4.00
Press return to continue.
inv(A_TA) :
+1.0000 +0.2803 -6.0000 +0.4773 -1.3939
+0.2803 +0.1069 -1.7727 +0.1933 -1.0818
-6.0000 -1.7727 +36.5000 -3.0455 +10.0455
+0.4773 +0.1933 -3.0455 +0.3629 -2.1574
-1.3939 -1.0818 +10.0455 -2.1574 +20.4692
inv(A_TA)*A_T :
+1.0000 +0.0000 +0.0000 +0.0000 +0.0000
+0.2803 -0.0909 +0.1326 +0.0076 -0.0492
-6.0000 -0.0000 -0.5000 -0.0000 +0.5000
+0.4773 -0.1818 +0.3068 -0.0682 -0.0568
-1.3939 +3.1818 -2.8485 +0.1515 +0.5152
x = inv(A_TA)*A_T*b :
+1.0000
+0.2803
-6.0000
+0.4773
-1.3939
Press return to continue.
x = inv(A_TA)*A_T*b :
+1.00
+0.28
-6.00
+0.48
-1.39
The coefficients a, b, c, d, e, of the curve are :
+1.00x**2 +0.28y**2 -6.00x +0.48y -1.39 = 0
Press return to continue.