Aller au contenu

Mathc matrices/c24b

Un livre de Wikilivres.


Application


Installer et compiler ces fichiers dans votre répertoire de travail.


c05a.c
/* ------------------------------------ */
/*  Save as :   c05a.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RA R5
#define   CA C2
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
{
double a[RA*(CA)]={
  2,  0,
  0,  3,
  0,  0,
  4,  5,
  1,  0
};

double x[RA*(C1)]={
 -1, 
  2, 
 -3,
 -3,
 -1,
};

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(" 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);      
}
/* ------------------------------------ */
int main(void)
{
	
  fun();

  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */


Trouver une projection sur un sous-espace vectoriel par une application linéaire :

  • A est un sous espace de R5. Trouver une matrice V qui projette un vecteur x sur R5.
          Proj(x) =  V * x
                V =  A * inv(AT*A) * AT 
                


Exemple de sortie écran :
 ------------------------------------ 
 A is subspace of R5              

 Find a transformation matrix for    
 a projection onto R5  :          

 Proj(x) =  A * inv(AT*A) * AT * x 

 A :
 +2.0  +0.0 
 +0.0  +3.0 
 +0.0  +0.0 
 +4.0  +5.0 
 +1.0  +0.0 

 Press return to continue. 


 ------------------------------------ 
 AT :
 +2.0  +0.0  +0.0  +4.0  +1.0 
 +0.0  +3.0  +0.0  +5.0  +0.0 

 ATA :
+21.0 +20.0 
+20.0 +34.0 

 inv(AT*A) :
+0.1083 -0.0637 
-0.0637 +0.0669 

 inv(AT*A)*AT :
+0.2166 -0.1911 +0.0000 +0.1146 +0.1083 
-0.1274 +0.2006 +0.0000 +0.0796 -0.0637 

 V = A*inv(AT*A)*AT :
+0.4331 -0.3822 +0.0000 +0.2293 +0.2166 
-0.3822 +0.6019 +0.0000 +0.2389 -0.1911 
+0.0000 +0.0000 +0.0000 +0.0000 +0.0000 
+0.2293 +0.2389 +0.0000 +0.8567 +0.1146 
+0.2166 -0.1911 +0.0000 +0.1146 +0.1083 

 Press return to continue. 


 ------------------------------------ 
 V is transformation matrix for     
 a projection onto a subspace R5 :


+0.4331 -0.3822 +0.0000 +0.2293 +0.2166 
-0.3822 +0.6019 +0.0000 +0.2389 -0.1911 
+0.0000 +0.0000 +0.0000 +0.0000 +0.0000 
+0.2293 +0.2389 +0.0000 +0.8567 +0.1146 
+0.2166 -0.1911 +0.0000 +0.1146 +0.1083 

 Proj(x) =  A * inv(AT*A) * AT * x 

 Proj(x) =  V                  * x :
-2.1019 
+1.0605 
+0.0000 
-2.4363 
-1.0510 

 Press return to continue.