Mathc complexes/a313
Apparence
Installer et compiler ces fichiers dans votre répertoire de travail.
c03d.c |
---|
/* ------------------------------------ */
/* Xave as : c03d.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R5
#define CA C3
#define FACTOR_E +1.E-2
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
int r = RA;
int c = CA;
double a[RA*(CA*C2)] ={
+42, +37, +25, -20, +27, +98,
+2, +97, -44, -43, +57, -88,
+48, +81, -24, +57, +81, +28,
-17, +32, +94, +85, -67, -52,
-92, -67, -53, +91, -91, -77};
double t[RA*C2] ={
+3, +2,
+2, +9,
+5, +7,
-4, +9,
-3, -6};
double **A = ca_A_mZ(a, i_mZ(r,c));
double **b = ca_A_mZ(t, i_mZ(r,C1));
double **x = i_mZ(r,C1) ;
double **A_T = ctranspose_mZ(A,i_mZ(c,r));
double **V = i_mZ(r,c);
double **V_T = i_mZ(c,r);
double **U = i_mZ(r,c);
double **U_T = i_mZ(c,r); // :c,r
double **U_TA = i_mZ(c,c); // c,r r,c :c,c
double **U_TAr = i_mZ(c,r); // c,r :c,r
double **X = i_mZ(c,c); // c,r r,c :c,c U_TArV
double **invX = i_mZ(c,c); // c,r r,c :c,c invX
double **VinvX = i_mZ(r,c);
double **Pinv = i_mZ(r,r);
double **PinvA = i_mZ(r,c); // r,c | r,r
clrscrn();
printf(" A :");
p_mZ(A, S10,P2, S8,P2, C3);
printf(" b :");
p_mZ(b, S10,P2, S8,P2, C3);
stop();
clrscrn();
printf(" U :");
X_U_mZ(A_T,U,FACTOR_E);
p_mZ(U, S10,P4, S8,P4, C3);
printf(" V :");
X_V_mZ(A_T,V,FACTOR_E);
p_mZ(V, S10,P4, S8,P4, C3);
ctranspose_mZ(U,U_T);
ctranspose_mZ(V,V_T);
stop();
clrscrn();
printf(" X = U_T * A * V :");
mul_mZ(U_T, A, U_TA); // U_TA : c,c
c_mZ(U_TA, U_TAr ); // U_TAr : c,r
mul_mZ(U_TAr, V, X ); // V : r,c
p_mZ(X, S11,P4, S9,P4, C3);
printf(" invX :");
X_inv_mZ(X, invX);
pE_mZ(invX, S10,P4, S8,P4, C3);
stop();
clrscrn();
printf(" Copy/Past into the octave window.\n\n");
p_Octave_mZ(A,"A",P0, P0);
printf(" format short e\n");
printf(" pinv(A)\n\n");
stop();
clrscrn();
printf(" Pinv = V * invX * U_T:");
mul_mZ(V, invX, VinvX);
mul_mZ(VinvX, U_T, Pinv);
pE_mZ(Pinv, S13,P4, S13,P4, C2);
stop();
clrscrn();
printf(" Ide = Pinv * A ");
mul_mZ(Pinv, A, PinvA);
p_mZ(PinvA, S10,P4, S8,P4, C3);
stop();
clrscrn();
printf(" A x = b \n"
" Pinv A x = Pinv b \n"
" Ide x = Pinv b \n\n"
" x = Pinv b ");
mul_mZ(Pinv, b, x);
pE_mZ(x, S12,P4, S12,P4, C3);
stop();
f_mZ(A);
f_mZ(A_T);
f_mZ(b);
f_mZ(x);
f_mZ(V);
f_mZ(V_T);
f_mZ(U);
f_mZ(U_T);
f_mZ(U_TA);
f_mZ(U_TAr);
f_mZ(X);
f_mZ(invX);
f_mZ(VinvX);
f_mZ(Pinv);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Exemple de sortie écran :
A :
+42.00 +37.00i +25.00 -20.00i +27.00 +98.00i
+2.00 +97.00i -44.00 -43.00i +57.00 -88.00i
+48.00 +81.00i -24.00 +57.00i +81.00 +28.00i
-17.00 +32.00i +94.00 +85.00i -67.00 -52.00i
-92.00 -67.00i -53.00 +91.00i -91.00 -77.00i
b :
+3.00 +2.00i
+2.00 +9.00i
+5.00 +7.00i
-4.00 +9.00i
-3.00 -6.00i
Press return to continue.
U :
-0.3763 -0.1696i -0.0776 -0.0081i +0.3221 +0.0551i
-0.1127 +0.2837i -0.0031 -0.5133i -0.6874 +0.2805i
-0.2390 +0.0887i -0.1350 -0.6089i +0.4249 -0.0450i
+0.3290 -0.2915i -0.4375 -0.2391i -0.2169 -0.3256i
+0.6915 +0.0000i +0.3046 +0.0000i +0.0803 -0.0000i
V :
+0.4175 -0.0169i -0.4826 -0.6178i -0.2673 +0.3733i
-0.2643 +0.4423i -0.3892 -0.3554i +0.5643 -0.3718i
+0.7483 +0.0000i +0.3280 -0.0000i +0.5767 +0.0000i
+0.0000 +0.0000i +0.0000 +0.0000i +0.0000 +0.0000i
+0.0000 +0.0000i +0.0000 +0.0000i +0.0000 +0.0000i
Press return to continue.
X = U_T * A * V :
-193.5953-190.1971i -0.0000 +0.0000i +0.0000 +0.0000i
-0.0000 -0.0000i +85.7999+155.3892i -0.0000 +0.0000i
-0.0000 -0.0000i -0.0000 +0.0000i +13.0770+127.2968i
invX :
-2.6284e-03+2.5823e-03i +0.0000e+00+0.0000e+00i +0.0000e+00+0.0000e+00i
+0.0000e+00+0.0000e+00i +2.7232e-03-4.9318e-03i +0.0000e+00+0.0000e+00i
+0.0000e+00+0.0000e+00i +0.0000e+00+0.0000e+00i +7.9857e-04-7.7736e-03i
Press return to continue.
Copy/Past into the octave window.
A=[
+42+37*i,+25-20*i,+27+98*i;
+2+97*i,-44-43*i,+57-88*i;
+48+81*i,-24+57*i,+81+28*i;
-17+32*i,+94+85*i,-67-52*i;
-92-67*i,-53+91*i,-91-77*i]
format short e
pinv(A)
Press return to continue.
Pinv = V * invX * U_T:
+1.5358e-03 -7.3675e-05i -1.0888e-03 -4.4558e-03i
-3.5156e-04 -8.5254e-04i -5.8943e-04 +2.7916e-03i
+2.5786e-04 -2.3970e-03i +2.3535e-05 +3.7559e-03i
+0.0000e+00 +0.0000e+00i +0.0000e+00 +0.0000e+00i
+0.0000e+00 +0.0000e+00i +0.0000e+00 +0.0000e+00i
+1.5505e-03 -1.7940e-03i -2.8964e-04 -9.2592e-04i
-1.0823e-03 -3.4607e-03i +3.4475e-03 -1.6049e-03i
+1.9035e-03 -1.4092e-03i +1.4546e-04 +2.1057e-03i
+0.0000e+00 +0.0000e+00i +0.0000e+00 +0.0000e+00i
+0.0000e+00 +0.0000e+00i +0.0000e+00 +0.0000e+00i
-1.8414e-03 +1.1797e-03i
-1.3623e-03 -1.3621e-03i
-1.0511e-03 +4.8354e-04i
+0.0000e+00 +0.0000e+00i
+0.0000e+00 +0.0000e+00i
Press return to continue.
Ide = Pinv * A
+1.0000 -0.0000i +0.0000 +0.0000i +0.0000 -0.0000i
-0.0000 -0.0000i +1.0000 -0.0000i +0.0000 +0.0000i
-0.0000 -0.0000i -0.0000 -0.0000i +1.0000 +0.0000i
+0.0000 +0.0000i +0.0000 +0.0000i +0.0000 +0.0000i
+0.0000 +0.0000i +0.0000 +0.0000i +0.0000 +0.0000i
Press return to continue.
A x = b
Pinv A x = Pinv b
Ide x = Pinv b
x = Pinv b
+8.5083e-02 -5.3704e-03i
-1.0271e-02 +2.1845e-02i
-2.2285e-02 +5.0690e-03i
+0.0000e+00 +0.0000e+00i
+0.0000e+00 +0.0000e+00i
Press return to continue.