Mathc matrices/c22t
Apparence
Sommaire ◀ Utilise la commande "Retour en Arrière" de ton navigateur.
Installer et compiler ces fichiers dans votre répertoire de travail.
c00c.c |
---|
/* ------------------------------------ */
/* Save as : c00c.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R3
#define CA C2
#define Cb C1
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
{
double ab[RA*(CA+Cb)]={
1, -1, 4,
3, 2, 1,
-2, 4, 3
};
double **Ab = ca_A_mR(ab,i_Abr_Ac_bc_mR(RA,CA,Cb));
double **A = c_Ab_A_mR(Ab,i_mR(RA,CA));
double **b = c_Ab_b_mR(Ab,i_mR(RA,Cb));
double **Q = i_mR(RA,CA);
double **R = i_mR(CA,CA);
double **invR = i_mR(CA,CA);
double **Q_T = i_mR(CA,RA);
double **invR_Q_T = i_mR(CA,RA);
double **x = i_mR(CA,Cb); // x invR * Q_T * b
clrscrn();
printf("Unique Least Squares Solution :\n\n");
printf(" A :");
p_mR(A,S5,P1,C7);
printf(" b :");
p_mR(b,S5,P1,C7);
printf(" Ab :");
p_mR(Ab,S5,P1,C7);
stop();
clrscrn();
QR_mR(A,Q,R);
printf(" Q :");
p_mR(Q,S3,P4,C6);
printf(" R :");
p_mR(R,S10,P4,C6);
stop();
clrscrn();
transpose_mR(Q,Q_T);
printf(" Q_T :");
pE_mR(Q_T,S3,P4,C6);
inv_mR(R,invR);
printf(" invR :");
pE_mR(invR,S10,P4,C6);
stop();
clrscrn();
printf(" Solving this system yields a unique\n"
" least squares solution, namely \n\n");
mul_mR(invR,Q_T,invR_Q_T);
mul_mR(invR_Q_T,b,x);
printf(" x = invR * Q_T * b :");
p_mR(x,S10,P4,C6);
stop();
f_mR(A);
f_mR(b);
f_mR(Ab);
f_mR(Q);
f_mR(Q_T);
f_mR(R);
f_mR(invR);
f_mR(invR_Q_T);
f_mR(x);
}
/* ------------------------------------ */
int main(void)
{
fun();
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Le nombre de lignes doit être supérieurs aux nombres de colonnes. La fonction gauss-jordan ne fonctionne pas dans cette situation.
Exemple de sortie écran :
-----------------------------------
Unique Least Squares Solution :
A :
+1.0 -1.0
+3.0 +2.0
-2.0 +4.0
b :
+4.0
+1.0
+3.0
Ab :
+1.0 -1.0 +4.0
+3.0 +2.0 +1.0
-2.0 +4.0 +3.0
Press return to continue.
-----------------------------------
Q :
+0.2673 -0.1741
+0.8018 +0.5858
-0.5345 +0.7916
R :
+3.7417 -0.8018
-0.0000 +4.5119
Press return to continue.
-----------------------------------
Q_T :
+2.6726e-01 +8.0178e-01 -5.3452e-01
-1.7414e-01 +5.8575e-01 +7.9156e-01
invR :
+2.6726e-01 +4.7494e-02
-0.0000e+00 +2.2164e-01
Press return to continue.
-----------------------------------
Solving this system yields a unique
least squares solution, namely
x = invR * Q_T * b :
+0.1789
+0.5018
Press return to continue.