Mathc matrices/c25g
Installer et compiler ces fichiers dans votre répertoire de travail.
c03b.c |
---|
/* ------------------------------------ */
/* Save as : c03b.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R3
#define CA C2
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
{
double tA[RA*CA]={
+0.078326044999, -0.989057126856,
+0.704934404989, +0.143625457365,
+0.704934404989, -0.033730221048
};
double tx[RA*C1]={
+5.0000,
+8.0000,
-8.0000,
};
double **A = ca_A_mR(tA,i_mR(RA,CA));
double **AT = i_mR(CA,RA);
double **ATA = i_mR(CA,CA); // AT*A
double **invATA = i_mR(CA,CA); // inv(AT*A)
double **invATA_AT = i_mR(CA,RA); // inv(AT*A)*AT
double **V = i_mR(RA,RA); // inv(AT*A)*AT
double **AAT = i_mR(RA,RA);
double **x = ca_A_mR(tx,i_mR(RA,C1));
double **Vx = i_mR(RA,C1);
clrscrn();
printf(" A is subspace of R%d \n\n"
" Find a transformation matrix for \n"
" a projection onto R%d : \n\n"
" Proj(x) = A * inv(AT*A) * AT * x \n\n",RA,RA);
printf(" A :");
p_mR(A,S5,P4,C7);
printf(" Compute Proj(x) with : \n\n"
" x :");
p_mR(x,S5,P4,C7);
stop();
clrscrn();
printf(" AT :");
p_mR(transpose_mR(A,AT),S5,P4,C7);
printf(" ATA :");
p_mR(mul_mR(AT,A,ATA),S5,P4,C7);
printf(" inv(AT*A) :");
p_mR(inv_mR(ATA,invATA),S5,P4,C7);
printf(" inv(AT*A)*AT :");
p_mR(mul_mR(invATA,AT,invATA_AT),S5,P4,C7);
printf(" V = A*inv(AT*A)*AT :");
p_mR(mul_mR(A,invATA_AT,V),S5,P4,C7);
stop();
clrscrn();
printf(" V is transformation matrix for \n"
" a projection onto a subspace R%d :\n\n",RA);
p_mR(V,S5,P4,C7);
printf(" Proj(x) = A * inv(AT*A) * AT * x \n\n");
printf(" Proj(x) = V * x :");
p_mR(mul_mR(V,x,Vx),S5,P4,C7);
stop();
clrscrn();
printf(" Proj(x) = A * inv(AT*A) * AT * x :");
p_mR(Vx,S5,P4,C7);
printf(" A * AT :");
p_mR(mul_mR(A,AT,AAT),S5,P4,C7);
printf(" Proj(x) = A * AT * x :");
p_mR(mul_mR(AAT,x,Vx),S5,P4,C7);
f_mR(A);
f_mR(AT);
f_mR(ATA); // AT*A
f_mR(invATA); // inv(AT*A)
f_mR(invATA_AT); // inv(AT*A)*AT
f_mR(V); // A*inv(AT*A)*AT
f_mR(AAT);
f_mR(x);
f_mR(Vx);
}
/* ------------------------------------ */
int main(void)
{
fun();
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Présentation deux deux algorithmes pour calculer la matrice de projection de x sur Rn quand la matrice A est un sous espace orthonormale de Rn. (Id) Proj(x) = A * inv(AT*A) * AT * x : Proj(x) = A * AT * x :
Exemple de sortie écran :
--------------------------------
A is subspace of R3
Find a transformation matrix for
a projection onto R3 :
Proj(x) = A * inv(AT*A) * AT * x
A :
+0.0783 -0.9891
+0.7049 +0.1436
+0.7049 -0.0337
Compute Proj(x) with :
x :
+5.0000
+8.0000
-8.0000
Press return to continue.
--------------------------------
AT :
+0.0783 +0.7049 +0.7049
-0.9891 +0.1436 -0.0337
ATA :
+1.0000 -0.0000
-0.0000 +1.0000
inv(AT*A) :
+1.0000 -0.0000
-0.0000 +1.0000
inv(AT*A)*AT :
+0.0783 +0.7049 +0.7049
-0.9891 +0.1436 -0.0337
V = A*inv(AT*A)*AT :
+0.9844 -0.0868 +0.0886
-0.0868 +0.5176 +0.4921
+0.0886 +0.4921 +0.4981
Press return to continue.
--------------------------------
V is transformation matrix for
a projection onto a subspace R3 :
+0.9844 -0.0868 +0.0886
-0.0868 +0.5176 +0.4921
+0.0886 +0.4921 +0.4981
Proj(x) = A * inv(AT*A) * AT * x
Proj(x) = V * x :
+3.5185
-0.2304
+0.3950
Press return to continue.
--------------------------------
Proj(x) = A * inv(AT*A) * AT * x :
+3.5185
-0.2304
+0.3950
A * AT :
+0.9844 -0.0868 +0.0886
-0.0868 +0.5176 +0.4921
+0.0886 +0.4921 +0.4981
Proj(x) = A * AT * x :
+3.5185
-0.2304
+0.3950