Aller au contenu

Mathc complexes/a250

Un livre de Wikilivres.


Application


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


c04a.c
/* ------------------------------------ */
/*  Save as :   c04a.c                  */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RA R4
#define   CA C2
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double a[RA*(CA*C2)]={
 -2,-3, -4,-2,
  1, 0, -3,-5,
  0, 1, -6,-4,
  3, 5, -1,-0,  
};

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

double **A           = ca_A_mZ(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 **X           = ca_A_mZ(x, i_mZ(RA,C1));
double **VX          =            i_mZ(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_mZ(A,S5,P1,S5,P1,C7);
  stop();
  
  clrscrn();
  printf(" AT :");
  p_mZ(ctranspose_mZ(A,AT),S5,P1,S5,P1,C7);
  printf(" ATA :");
  p_mZ(mul_mZ(AT,A,ATA),S5,P1,S5,P1,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(" X :");
  p_mZ(X,S5,P1,S5,P1,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();    
  
  
  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(X); 
  f_mZ(VX);         

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


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

  • A est un sous espace de R4. Trouver une matrice V qui projette un vecteur x sur R4.
          Proj(x) =  V * x
                V =  A * inv(AT*A) * AT 
       
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 :
 -2.0 -3.0i  -4.0 -2.0i 
 +1.0 +0.0i  -3.0 -5.0i 
 +0.0 +1.0i  -6.0 -4.0i 
 +3.0 +5.0i  -1.0 +0.0i 

 Press return to continue. 


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

 ATA :
+49.0 +0.0i  +4.0 -2.0i 
 +4.0 +2.0i +107.0 +0.0i 

 inv(AT*A) :
+0.0205+0.0000i -0.0008+0.0004i 
-0.0008-0.0004i +0.0094+0.0000i 

 inv(AT*A)*AT :
-0.0387+0.0584i +0.0209-0.0050i +0.0031-0.0258i +0.0622-0.1028i 
-0.0348+0.0172i -0.0289+0.0465i -0.0567+0.0383i -0.0136+0.0027i 

 V = A*inv(AT*A)*AT :
+0.4264+0.0000i +0.1520-0.1809i +0.2196+0.0027i -0.3732+0.0354i 
+0.1520+0.1809i +0.3402+0.0000i +0.3645+0.1426i +0.1164-0.0429i 
+0.2196-0.0027i +0.3645-0.1426i +0.5191-0.0000i +0.1951+0.1005i 
-0.3732-0.0354i +0.1164+0.0429i +0.1951-0.1005i +0.7143+0.0000i 

 Press return to continue. 


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


+0.4264+0.0000i +0.1520-0.1809i +0.2196+0.0027i -0.3732+0.0354i 
+0.1520+0.1809i +0.3402+0.0000i +0.3645+0.1426i +0.1164-0.0429i 
+0.2196-0.0027i +0.3645-0.1426i +0.5191-0.0000i +0.1951+0.1005i 
-0.3732-0.0354i +0.1164+0.0429i +0.1951-0.1005i +0.7143+0.0000i 

 X :
 -1.0 -3.0i 
 +2.0 -4.0i 
 -3.0 -5.0i 
 -1.0 -2.0i 

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

 Proj(x) =  V                  * x :
-1.0475-2.6443i 
+0.4886-4.4384i 
-1.6203-5.4855i 
-1.1310-1.3276i 

 Press return to continue.