Aller au contenu

Mathc matrices/c25f

Un livre de Wikilivres.


Application


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

c03a.c
/* ------------------------------------ */
/*  Save as :   c03a.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RA R4
#define   CA C2
/* ------------------------------------ */
/* ------------------------------------ */
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 :


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