Mathc matrices/c12b9
Installer ce fichier dans votre répertoire de travail.
c00a.c |
---|
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r,int c)
{
double **A = r_mR( i_mR(r,c),9.);
double **U = i_mR(r,r);
double **U_T = i_mR(r,r);
double **U_TA = i_mR(r,c);
double **V = i_mR(c,c);
double **VS_T = i_mR(c,r); /* cc cr VS_T */
double **S = i_mR(r,c);
double **S_T = i_mR(c,r);
double **invS_T = i_mR(c,r);
double **Pinv = i_mR(c,r); /* cc cr rr VS_TU_T */
double **Ide = i_mR(r,r); /* rc cc cr rr AVS_TU_T */
clrscrn();
printf(" Copy/Past into the octave windows \n\n\n");
p_Octave_mR(A,"A",P2);
printf("pinv(A)\n\n\n");
stop();
clrscrn();
svd_U_Cn_mR(A,U);
svd_V_Cn_mR(A,V);
transpose_mR(U,U_T);
/* S = U_T * B * V */
mul_mR(U_T,A,U_TA);
mul_mR(U_TA,V,S);
transpose_mR(S,S_T); /* S =i_mR(r,c); S_T = i_mR(c,r); */
inv_svd_mR(S_T,invS_T);
printf(" PseudoInverse = V * invS_T * U_T ");
mul_mR(V,invS_T,VS_T);
mul_mR(VS_T,U_T,Pinv);
pE_mR(Pinv,S10,P6,C10);
printf(" Ide = A * PseudoInverse ");
mul_mR(A,Pinv,Ide);
p_mR(Ide,S10,P6,C10);
f_mR(A);
f_mR(U);
f_mR(U_T);
f_mR(U_TA);
f_mR(V);
f_mR(VS_T);
f_mR(S);
f_mR(S_T);
f_mR(invS_T);
f_mR(Pinv);
f_mR(Ide);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
int i;
do
{
i = rp_I(R3)+R1;
fun(i,i+C3);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Cet version fonctionne quand il y a plus de colonnes que de lignes..
svd_U_Cn_mR(A,U); svd_V_Cn_mR(A,V);
Exemple de sortie écran :
Copy/Past into the octave windows
A=[
+6.00,+6.00,-7.00,+6.00,-1.00,+8.00;
-1.00,-5.00,+2.00,+2.00,-1.00,+6.00;
+8.00,+2.00,-9.00,-1.00,+8.00,+2.00]
pinv(A)
Press return to continue.
PseudoInverse = V * invS_T * U_T
+9.531179e-03 -6.537687e-04 +3.113016e-02
+5.162158e-02 -9.532050e-02 -3.529172e-02
-1.554124e-02 +1.629089e-02 -2.983236e-02
+4.198733e-02 +8.578984e-03 -2.732446e-02
-4.187504e-02 +2.320802e-02 +6.432776e-02
+2.881197e-02 +8.270200e-02 +5.552163e-03
Ide = A * PseudoInverse
+1.000000 -0.000000 -0.000000
+0.000000 +1.000000 -0.000000
+0.000000 +0.000000 +1.000000
Press return to continue
Press X to stop