Mathc matrices/c22m
Sommaire ◀ Utilise la commande "Retour en Arrière" de ton navigateur.
Installer et compiler ces fichiers dans votre répertoire de travail.
c00b.c |
---|
/* ------------------------------------ */
/* Save as : c00b.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r,int rn)
{
double **A = i_mR(r+rn,r);
double **b = i_mR(r+rn,C1);
double **Ab = i_Abr_Ac_bc_mR(r+rn,r,C1);
double **Q = i_mR(r+rn,r);
double **R = i_mR(r,r);
double **invR = i_mR(r,r);
double **Q_T = i_mR(r,r+rn);
double **invR_Q_T = i_mR(r,r+rn);
double **x = i_mR(r,C1); // x invR * Q_T * b
clrscrn();
printf(" Find the unique Least Squares Solution :\n\n");
printf(" A :");
p_mR(r_mR(A,999.),S5,P0,C7);
printf(" b :");
p_mR(r_mR(b,999.),S5,P0,C7);
printf(" Ab :");
c_A_b_Ab_mR(A,b,Ab);
p_mR(Ab,S5,P0,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);
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)
{
time_t t;
srand(time(&t));
do
{
fun(rp_I(R3)+R1,rp_I(C3));
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Ici 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 :
-----------------------------------
Find the unique Least Squares Solution :
A :
-267 +417
-741 -89
+557 -127
+798 +239
-130 -696
b :
-763
-784
+513
-861
+13
Ab :
-267 +417 -763
-741 -89 -784
+557 -127 +513
+798 +239 -861
-130 -696 +13
Press return to continue.
-----------------------------------
Q :
-0.2121 +0.5234
-0.5887 -0.0139
+0.4425 -0.2177
+0.6340 +0.1834
-0.1033 -0.8030
R :
+1258.6989 +131.1457
-0.0000 +849.8687
Press return to continue.
-----------------------------------
Q_T :
-2.1212e-01 -5.8870e-01 +4.4252e-01 +6.3399e-01 -1.0328e-01
+5.2340e-01 -1.3878e-02 -2.1772e-01 +1.8339e-01 -8.0301e-01
invR :
+7.9447e-04 -1.2260e-04
-0.0000e+00 +1.1767e-03
Press return to continue.
-----------------------------------
Solving this system yields a unique
least squares solution, namely
x = invR * Q_T * b :
+0.3228
-0.7866
Press return to continue
Press X to stop