Mathc matrices/c23t
Installer et compiler ces fichiers dans votre répertoire de travail.
c03a.c |
---|
/* ------------------------------------ */
/* Save as : c03a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R3
#define CA C2
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double a[RA*(CA)]={
-2, -3,
1, 0,
0, 1
};
double x[RA*C1]={
-1,
2,
-3
};
double **A = ca_A_mR(a,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 **X = ca_A_mR(x,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,P1,C7);
stop();
clrscrn();
printf(" AT :");
p_mR(transpose_mR(A,AT),S5,P1,C7);
printf(" ATA :");
p_mR(mul_mR(AT,A,ATA),S5,P1,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(" X :");
p_mR(X,S5,P1,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();
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(X);
f_mR(VX);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Trouver une projection sur un sous-espace vectoriel par une application linéaire :
- A est un sous espace de R3. Trouver une matrice V qui projette un vecteur x sur R3.
Proj(x) = V * x V = A * inv(AT*A) * AT 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 :
-2.0 -3.0
+1.0 +0.0
+0.0 +1.0
Press return to continue.
------------------------------------
AT :
-2.0 +1.0 +0.0
-3.0 +0.0 +1.0
ATA :
+5.0 +6.0
+6.0 +10.0
inv(AT*A) :
+0.7143 -0.4286
-0.4286 +0.3571
inv(AT*A)*AT :
-0.1429 +0.7143 -0.4286
-0.2143 -0.4286 +0.3571
V = A*inv(AT*A)*AT :
+0.9286 -0.1429 -0.2143
-0.1429 +0.7143 -0.4286
-0.2143 -0.4286 +0.3571
Press return to continue.
------------------------------------
V is transformation matrix for
a projection onto a subspace R3 :
+0.9286 -0.1429 -0.2143
-0.1429 +0.7143 -0.4286
-0.2143 -0.4286 +0.3571
X :
-1.0
+2.0
-3.0
Proj(x) = A * inv(AT*A) * AT * x
Proj(x) = V * x :
-0.5714
+2.8571
-1.7143
Press return to continue.