Aller au contenu

Mathc complexes/014

Un livre de Wikilivres.

Application

Installer et compiler ce fichier dans votre répertoire de travail.

c00a.c
/* ------------------------------------ */
/*  Save as :   c00a.c                  */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
void fun(int r)
{
double **A      = rdiag_mZ(i_mZ(r,r),9.);
double **Q      =          i_mZ(r,r);
double **R      =          i_mZ(r,r);

  clrscrn();
  printf(" A :");
  P_mZ(A, S3,P0, S2,P0, C6);

  printf(" Copy/Past into the octave windows \n\n");
  p_Octave_mZ(A,"a",P0,P0);
  printf(" [Q, R] = qr (a,0) \n\n");
  stop();
 
  clrscrn();
  QR_mZ(A,Q,R);    
  printf(" Q :");
  p_mZ(Q, S8,P4, S8,P4, C6);
  printf(" R :");
  p_mZ(R, S8,P4, S8,P4, C6);
  stop();
  
  clrscrn();
  printf(" A :");
  p_mZ(A, S8,P4, S8,P4, C6); 
  
  printf(" A = Q * R  :");  
  mul_mZ(Q,R, A);
  p_mZ(A, S8,P4, S8,P4, C6); 
  
  f_mZ(A);
  f_mZ(Q);
  f_mZ(R);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  fun(rp_I(R3)+R1);

} while(stop_w());

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


La QR décomposition d'une matrice diagonale


Exemple de sortie écran :

 A :
 -3,-3,  +0,+0,  +0,+0,  +0,+0, 
 +0,+0,  -1,-3,  +0,+0,  +0,+0, 
 +0,+0,  +0,+0,  -5,-4,  +0,+0, 
 +0,+0,  +0,+0,  +0,+0,  +5,+4  

 Copy/Past into the octave windows 

 a=[
-3-3*i,+0+0*i,+0+0*i,+0+0*i;
+0+0*i,-1-3*i,+0+0*i,+0+0*i;
+0+0*i,+0+0*i,-5-4*i,+0+0*i;
+0+0*i,+0+0*i,+0+0*i,+5+4*i]

 [Q, R] = qr (a,0) 

 Press return to continue. 


 Q :
 -0.7071 -0.7071i  +0.0000 +0.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i 
 +0.0000 +0.0000i  -0.3162 -0.9487i  +0.0000 +0.0000i  +0.0000 +0.0000i 
 +0.0000 +0.0000i  +0.0000 +0.0000i  -0.7809 -0.6247i  +0.0000 +0.0000i 
 +0.0000 +0.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i  +0.7809 +0.6247i 

 R :
 +4.2426 +0.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i 
 +0.0000 +0.0000i  +3.1623 +0.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i 
 +0.0000 +0.0000i  +0.0000 +0.0000i  +6.4031 +0.0000i  +0.0000 +0.0000i 
 +0.0000 +0.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i  +6.4031 +0.0000i 

 Press return to continue. 


 A :
 -3.0000 -3.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i 
 +0.0000 +0.0000i  -1.0000 -3.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i 
 +0.0000 +0.0000i  +0.0000 +0.0000i  -5.0000 -4.0000i  +0.0000 +0.0000i 
 +0.0000 +0.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i  +5.0000 +4.0000i 

 A = Q * R  :
 -3.0000 -3.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i 
 +0.0000 +0.0000i  -1.0000 -3.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i 
 +0.0000 +0.0000i  +0.0000 +0.0000i  -5.0000 -4.0000i  +0.0000 +0.0000i 
 +0.0000 +0.0000i  +0.0000 +0.0000i  +0.0000 +0.0000i  +5.0000 +4.0000i 


 Press   return to continue
 Press X return to stop