Aller au contenu

Mathc complexes/a240

Un livre de Wikilivres.


Application


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


c03a.c
/* ------------------------------------ */
/*  Save as :   c03a.c                  */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RA R4
#define   CA C2
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
{
double **T           = r_Q_mZ(i_mZ(R4,C4), 9);                      
double **A           = i_mZ(RA,CA);
double **AT          = i_mZ(CA,RA);
double **ATA         = i_mZ(CA,CA); //         AT*A
double **invATA      = i_mZ(CA,CA); //     inv(AT*A)
double **invATA_AT   = i_mZ(CA,RA); //     inv(AT*A)*AT
double **V           = i_mZ(RA,RA); //     inv(AT*A)*AT

double **AAT         = i_mZ(RA,RA);  

double **x           = r_mZ(i_mZ(RA,C1),9.);
double **Vx          =      i_mZ(RA,C1);
  
  c_c_mZ(T,C1,A,C1); 
  c_c_mZ(T,C2,A,C2);
    
  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_mZ(A,S5,P4,S5,P4,C7);
  printf(" Compute Proj(x) with : \n\n"
         " x :");
  p_mZ(x,S5,P4,S5,P4,C7);
  stop();
  
  clrscrn();
  printf(" AT :");
  p_mZ(ctranspose_mZ(A,AT),S5,P4,S5,P4,C7);
  printf(" ATA :");
  p_mZ(mul_mZ(AT,A,ATA),S5,P4,S5,P4,C7);
  printf(" inv(AT*A) :");
  p_mZ(invgj_mZ(ATA,invATA),S5,P4,S5,P4,C7);  
  printf(" inv(AT*A)*AT :");
  
  p_mZ(mul_mZ(invATA,AT,invATA_AT),S5,P4,S5,P4,C7); 
  printf(" V = A*inv(AT*A)*AT :");
  p_mZ(mul_mZ(A,invATA_AT,V),S5,P4,S5,P4,C7);    
  stop();  
  
  clrscrn();
  printf(" V is transformation matrix for      \n"
         " a projection onto a subspace R%d :\n\n",RA);
  p_mZ(V,S5,P4,S5,P4,C7); 
  printf(" Proj(x) =  A * inv(AT*A) * AT * x \n\n"); 
  printf(" Proj(x) =  V                  * x :");  
  p_mZ(mul_mZ(V,x,Vx),S5,P4,S5,P4,C7); 
  stop();  
  
  clrscrn();
  printf(" Proj(x) =  A * inv(AT*A) * AT * x :");  
  p_mZ(Vx,S5,P4,S5,P4,C7); 
  printf(" A * AT :"); 
  p_mZ(mul_mZ(A,AT,AAT),S5,P4,S5,P4,C7); 
  printf(" Proj(x) =  A * AT * x :");   
  p_mZ(mul_mZ(AAT,x,Vx),S5,P4,S5,P4,C7);
  
  
  f_mZ(A);
  f_mZ(AT);
  f_mZ(ATA);       //         AT*A
  f_mZ(invATA);    //     inv(AT*A)
  f_mZ(invATA_AT); //     inv(AT*A)*AT
  f_mZ(V);         //   A*inv(AT*A)*AT  
  
  f_mZ(AAT);
   
  f_mZ(x); 
  f_mZ(Vx);   
  
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  fun();

} while(stop_w());

  return 0;
}

/* ------------------------------------ */
/* ------------------------------------ */


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.1890-0.1890i +0.3379+0.3604i 
-0.5669+0.3780i -0.3491-0.2642i 
+0.2520-0.2520i +0.3927-0.0589i 
-0.3780-0.4410i -0.3832+0.5097i 

 Compute Proj(x) with : 

 x :
-1.0000+7.0000i 
+1.0000+1.0000i 
-8.0000+8.0000i 
-5.0000+2.0000i 

 Press return to continue. 


 ------------------------------------ 
 AT :
-0.1890+0.1890i -0.5669-0.3780i +0.2520+0.2520i -0.3780+0.4410i 
+0.3379-0.3604i -0.3491+0.2642i +0.3927+0.0589i -0.3832-0.5097i 

 ATA :
+1.0000+0.0000i -0.0000+0.0000i 
-0.0000+0.0000i +1.0000+0.0000i 

 inv(AT*A) :
+1.0000+0.0000i +0.0000+0.0000i 
+0.0000+0.0000i +1.0000+0.0000i 

 inv(AT*A)*AT :
-0.1890+0.1890i -0.5669-0.3780i +0.2520+0.2520i -0.3780+0.4410i 
+0.3379-0.3604i -0.3491+0.2642i +0.3927+0.0589i -0.3832-0.5097i 

 V = A*inv(AT*A)*AT :
+0.3154+0.0000i -0.1775+0.1420i +0.1115+0.0662i +0.2090-0.3222i 
-0.1775-0.1420i +0.6560+0.0000i -0.3596-0.1719i +0.0467-0.1137i 
+0.1115-0.0662i -0.3596+0.1719i +0.2847+0.0000i -0.1646+0.0288i 
+0.2090+0.3222i +0.0467+0.1137i -0.1646-0.0288i +0.7439+0.0000i 

 Press return to continue. 


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


+0.3154+0.0000i -0.1775+0.1420i +0.1115+0.0662i +0.2090-0.3222i 
-0.1775-0.1420i +0.6560+0.0000i -0.3596-0.1719i +0.0467-0.1137i 
+0.1115-0.0662i -0.3596+0.1719i +0.2847+0.0000i -0.1646+0.0288i 
+0.2090+0.3222i +0.0467+0.1137i -0.1646-0.0288i +0.7439+0.0000i 

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

 Proj(x) =  V                  * x :
-2.4565+4.5637i 
+6.0740-1.2838i 
-1.6915+2.4630i 
-4.7035+1.7019i 

 Press return to continue. 

 ------------------------------------ 
 Proj(x) =  A * inv(AT*A) * AT * x :
-2.4565+4.5637i 
+6.0740-1.2838i 
-1.6915+2.4630i 
-4.7035+1.7019i 

 A * AT :
+0.3154+0.0000i -0.1775+0.1420i +0.1115+0.0662i +0.2090-0.3222i 
-0.1775-0.1420i +0.6560+0.0000i -0.3596-0.1719i +0.0467-0.1137i 
+0.1115-0.0662i -0.3596+0.1719i +0.2847+0.0000i -0.1646+0.0288i 
+0.2090+0.3222i +0.0467+0.1137i -0.1646-0.0288i +0.7439+0.0000i 

 Proj(x) =  A * AT * x :
-2.4565+4.5637i 
+6.0740-1.2838i 
-1.6915+2.4630i 
-4.7035+1.7019i 


 Press   return to continue
 Press X return to stop