Mathc matrices/c25d

Un livre de Wikilivres.


Application


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

c02a.c
/* ------------------------------------ */
/*  Save as :   c02a.c                  */
/* ------------------------------------ */
#include "v_a.h" 
/* ------------------------------------ */
/* ------------------------------------ */
#define   RCB RC4
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
{
double **B      = r_Q_mR(  i_mR(RCB,RCB), 9);
double **invB   = inv_mR(B,i_mR(RCB,RCB));

double **b[RCB];

double **x      =   r_mR(i_mR(RCB,C1),9.);
double **x_b    =        i_mR(RCB,C1)    ;
int c;

/* ------------------------------------ */
/* ------------------------------------ */
  for(c=C0; c<csize_R(B); c++)
     {
      b[c] = i_mR(RCB,C1);      
      c_c_mR(B,(c+C1),b[c],C1); }

      
/* ------------------------------------ */
/* ------------------------------------ */      
  clrscrn();
  printf(" B is the change of basis matrix for the basis \"B\" \n\n"
         " B :             orthonormal matrix");
  p_mR(B,S10,P4,C7);
  printf("invB :              invB == B_T");
  p_mR(invB,S10,P4,C7);
  stop();  
  
/* ------------------------------------ */
/* ------------------------------------ */     
  clrscrn();
  printf(" x :");      
  p_mR(x,S10,P4,C6); 
  printf("  Compute x in the B basis :\n\n"
         " x_b         = invB * x :");
  p_mR(mul_mR(invB,x,x_b),S10,P4,C7);  
  stop();  
  
/* ------------------------------------ */
/* ------------------------------------ */  
  clrscrn();
  printf(" x :");      
  p_mR(x,S10,P4,C6); 
  
  printf("   b[1]       b[2]    ...           b[n]\n");
  p_mR(B,S10,P4,C7);
  
  printf(" Compute x in the B basis : \n\n"
         " x_b :                 x_b = <b[i],x>\n");
         
  for(c=C0; c<csize_R(B); c++)   
      printf("%+10.4f   <b[%d],x>\n",dot_R(b[c],x),c);
      
  printf("\n\n"); 
     
  stop();  
/* ------------------------------------ */
/* ------------------------------------ */   
  clrscrn(); 

  printf(" Compute x in the B basis : \n\n"
         " x_b  :                x_b = invB * x");      
  p_mR(x_b,S10,P4,C6); 
  
  printf(" x_b :                 x_b = <b[i],x>\n");
         
  for(c=C0; c<csize_R(B); c++)   
      printf("%+10.4f   <b[%d],x>\n",dot_R(b[c],x),c); 

   printf("\n\n");         
/* ------------------------------------ */
/* ------------------------------------ */

  for(c=C0; c<csize_R(B); c++)
  
       f_mR(b[c]); 

  f_mR(x);        
  f_mR(B);
  f_mR(invB);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  fun();

} while(stop_w());

  return 0;
}

/* ------------------------------------ */
/* ------------------------------------ */
Présentation de deux algorithmes pour calculer la valeur de x en base b


                 x_b = invB * x
                 x_b = <b[i],x>


 Pour changer la taille des vecteurs il suffit de modifier la valeur de :
#define   RCB RC4


Exemple de sortie écran :
 --------------------------------
 B is the change of basis matrix for the basis "B" 

 B :             orthonormal matrix
   +0.4815    -0.4999    +0.0651    +0.7169 
   +0.7223    +0.0673    +0.4906    -0.4828 
   +0.4815    +0.1882    -0.8482    -0.1151 
   -0.1204    -0.8427    -0.1889    -0.4896 

invB :              invB == B_T
   +0.4815    +0.7223    +0.4815    -0.1204 
   -0.4999    +0.0673    +0.1882    -0.8427 
   +0.0651    +0.4906    -0.8482    -0.1889 
   +0.7169    -0.4828    -0.1151    -0.4896 

 Press return to continue. 


 --------------------------------
 x :
   +6.0000 
   +6.0000 
   -4.0000 
   +1.0000 

  Compute x in the B basis :

 x_b         = invB * x :
   +5.1766 
   -4.1911 
   +6.5380 
   +1.3758 

 Press return to continue. 


 --------------------------------
 x :
   +6.0000 
   +6.0000 
   -4.0000 
   +1.0000 

   b[1]       b[2]    ...           b[n]

   +0.4815    -0.4999    +0.0651    +0.7169 
   +0.7223    +0.0673    +0.4906    -0.4828 
   +0.4815    +0.1882    -0.8482    -0.1151 
   -0.1204    -0.8427    -0.1889    -0.4896 

 Compute x in the B basis : 

 x_b :                 x_b = <b[i],x>
   +5.1766   <b[0],x>
   -4.1911   <b[1],x>
   +6.5380   <b[2],x>
   +1.3758   <b[3],x>


 Press return to continue. 


 --------------------------------
 Compute x in the B basis : 

 x_b  :                x_b = invB * x
   +5.1766 
   -4.1911 
   +6.5380 
   +1.3758 

 x_b :                 x_b = <b[i],x>
   +5.1766   <b[0],x>
   -4.1911   <b[1],x>
   +6.5380   <b[2],x>
   +1.3758   <b[3],x>



 Press return to continue
 Press X      to stop