Mathc matrices/c25f
Application
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c03a.c */
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
double **A = r_Q_mR(i_mR(RA,CA), 9);
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 = r_mR(i_mR(RA,C1),9.);
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)
time_t t;
 srand(time(&t));
do
 fun();
} while(stop_w());
 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 :
 Pour changer la taille des vecteurs il suffit de modifier la valeur de :

Exemple de sortie écran :
 A is subspace of R4 
 Find a transformation matrix for 
 a projection onto R4 : 
 Proj(x) = A * inv(AT*A) * AT * x 
 A :
+0.5644 +0.2555 
-0.5644 -0.2555 
+0.4704 -0.8737 
-0.3763 -0.3256 
 Compute Proj(x) with : 
 x :
-1.0000 
+3.0000 
+8.0000 
-5.0000 
 Press return to continue. 
 --------------------------------
 AT :
+0.5644 -0.5644 +0.4704 -0.3763 
+0.2555 -0.2555 -0.8737 -0.3256 
 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.5644 -0.5644 +0.4704 -0.3763 
+0.2555 -0.2555 -0.8737 -0.3256 
 V = A*inv(AT*A)*AT :
+0.3839 -0.3839 +0.0422 -0.2956 
-0.3839 +0.3839 -0.0422 +0.2956 
+0.0422 -0.0422 +0.9846 +0.1075 
-0.2956 +0.2956 +0.1075 +0.2476 
 Press return to continue. 
 --------------------------------
 V is transformation matrix for 
 a projection onto a subspace R4 :
+0.3839 -0.3839 +0.0422 -0.2956 
-0.3839 +0.3839 -0.0422 +0.2956 
+0.0422 -0.0422 +0.9846 +0.1075 
-0.2956 +0.2956 +0.1075 +0.2476 
 Proj(x) = A * inv(AT*A) * AT * x 
 Proj(x) = V * x :
+0.2802 
-0.2802 
+7.1708 
+0.8042 
 Press return to continue. 
 --------------------------------
 Proj(x) = A * inv(AT*A) * AT * x :
+0.2802 
-0.2802 
+7.1708 
+0.8042 
 A * AT :
+0.3839 -0.3839 +0.0422 -0.2956 
-0.3839 +0.3839 -0.0422 +0.2956 
+0.0422 -0.0422 +0.9846 +0.1075 
-0.2956 +0.2956 +0.1075 +0.2476 
 Proj(x) = A * AT * x :
+0.2802 
-0.2802 
+7.1708 
+0.8042

Mathc matrices/c25g
Application
Installer et compiler ces fichiers dans votre répertoire de travail.
/* Save as : c03b.c */
/* ------------------------------------ */
/* ------------------------------------ */
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 :
 Pour changer la taille des vecteurs il suffit de modifier la valeur de :
 #define RCQ RC4
 et de rajouter éventuellement de nouvelles lignes et colonnes.

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