Aller au contenu

Mathc matrices/08j

Un livre de Wikilivres.


Application

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

c00d.c
/* ------------------------------------ */
/*  Save as :   c00d.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   V    R1
/* ------------------------------------ */
#define   RAb  R2
#define   CA   C3
#define   Cb   C1
/* ------------------------------------ */
# define FREEV C2
/* ------------------------------------ */
/* ------------------------------------ */
#define  UARRAY FREEV
#define  VARRAY V
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double ab[RAb*(CA+C1)]={
 +692.0,  +524.0,   +86.0, -0.0, /* V[0]|0 */
   +0.0,    +0.0,    +0.0, -0.0     
};

double **Ab      = ca_A_mR(ab, i_Abr_Ac_bc_mR(RAb, CA, Cb));
double **Ab_free =             i_Abr_Ac_bc_mR(CA,  CA, Cb + FREEV);
double **b_free  =                       i_mR(CA,      Cb + FREEV); 

double **A       =    c_Ab_A_mR(Ab,      i_mR(RAb,     CA));  
double **At      = transpose_mR(A,       i_mR(CA,      RAb));  
/* ------------------------------------ */
double **u [UARRAY];
double **vt[VARRAY];
/* ------------------------------------ */
int c,r;

/*  Compute the free variables (b_free) */
      gj_PP_mR(Ab,NO);                
  put_zeroR_mR(Ab,Ab_free);           
  put_freeV_mR(Ab_free); 
      gj_PP_mR(Ab_free,YES); 
     c_Ab_b_mR(Ab_free,b_free);    

  clrscrn();
  printf(" Compute the orthogonal vectors to V :\n\n\n");
  for(c=C0; c<VARRAY; c++)
     {
      vt[c] = i_mR(CA,C1);     
      c_c_mR(At,(c+C1),vt[c],C1);
      
      printf(" v^t[%d]:",c);      
      p_mR(vt[c], S10,P4,C1);       
     }  
  stop();

  clrscrn();
  for(c=C0; c<UARRAY; c++)
     {
      u[c] = i_mR(CA,C1);      
      c_c_mR(b_free,(c+C2), u[c],C1); 
      
	  printf(" u[%d] :",c);      
      p_mR(u[c], S10,P4,C1);                 
     }  
   printf(" The free vectors of the system"
          " are the orthogonal vectors to V :\n\n\n");        
  stop();

  clrscrn();
  printf(" \n\n\n"
         " You can verify if"
         " the free vectors of the system\n"
         " are orthogonal to V :   \n\n"
         "          <u,v> = v^t u          \n\n");

  for(c=C0; c<VARRAY; c++) 
  
    for(r=C0;  r<UARRAY; r++) 

         printf(" v^t[%d] u[%d] = %+.4f\n",c,r, dot_R(vt[c],u[r])); 
              
  printf("\n\n\n");
  stop();
  
  f_mR(Ab);
  f_mR(Ab_free);
  f_mR(b_free);

/* --- Free the memory of the Arrays -- */
  for(c=C0; c<UARRAY; c++)
  
       f_mR( u[c]);        
      
  for(c=C0; c<VARRAY; c++)
  
       f_mR(vt[c]);      

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

Dans cet exemple, j'ajoute une ligne de zéros au système pour garantir la présence d'au moins deux lignes. La bibliothèque ne fonctionne pas avec les systèmes à une seule ligne. Si le produit scalaire de deux vecteurs est nul, cela signifie qu'ils sont orthogonaux.

Exemple de sortie écran :
 Compute the orthogonal vectors to V :


 v^t[0]:
 +692.0000 
 +524.0000 
  +86.0000 

 Press return to continue. 


 u[0] :
   -0.7572 
   +1.0000 
   +0.0000 

 u[1] :
   -0.1243 
   +0.0000 
   +1.0000 

 The free vectors of the system are the orthogonal vectors to V :


 Press return to continue. 


 You can verify if the free vectors of the system
 are orthogonal to V :   

          <u,v> = v^t u          

 v^t[0] u[0] = +0.0000
 v^t[0] u[1] = +0.0000



 Press return to continue.