Fonctions matricielles dans C. Matrices Non symétriques conjugués


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


c00a.c
/* ------------------------------------ */
/*  Save as :   c00a.c                  */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define FACTOR_E    +1.E-0         
#define RCA          RC3  
/* ------------------------------------ */
/* ------------------------------------ */
double **EigsValue_cosh2A_mZ(
double **EigsValue,
double **EigsValue_cosh2A
)
{
int  r;
int  c;

nb_Z cosh2A;

  for (   r=R1; r<EigsValue[R_SIZE][C0]; r++)
    for ( c=C1; c<EigsValue[C_SIZE][C0]; c+=C2)

        if(((r-R1)*C2)==c-C1)
          {
           cosh2A = cosh_Z(i_Z(2.*EigsValue[r][c],2.*EigsValue[r][c+C1]));
           
           EigsValue_cosh2A[r][c   ] = cosh2A.r;
           EigsValue_cosh2A[r][c+C1] = cosh2A.i;
          }
              
 return(EigsValue_cosh2A);
}
/* ------------------------------------ */
/* ------------------------------------ */
double **EigsValue_TwocoshAP2mns1_mZ(
double **EigsValue,
double **EigsValue_TwocoshAP2mns1
)
{
int  r;
int  c;

nb_Z cosha;
nb_Z mns1 = {1,0};

nb_Z TwocoshAP2mns1;

  for (   r=R1; r<EigsValue[R_SIZE][C0]; r++)
    for ( c=C1; c<EigsValue[C_SIZE][C0]; c+=C2)

        if(((r-R1)*C2)==c-C1)
          {
                    cosha = cosh_Z(i_Z( EigsValue[r][c], EigsValue[r][c+C1]));
           TwocoshAP2mns1 = sub_Z(smul_Z(2., mul_Z(cosha,cosha)),mns1); 
           
           EigsValue_TwocoshAP2mns1[r][c   ] = TwocoshAP2mns1.r;
           EigsValue_TwocoshAP2mns1[r][c+C1] = TwocoshAP2mns1.i;
          }
              
 return(EigsValue_TwocoshAP2mns1);
}
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
{                               
double **A                       = rE_mZ(i_mZ(RCA,RCA),999,+1.E-4);

double **V                       =       i_mZ(RCA,RCA);
double **invV                    =       i_mZ(RCA,RCA);
double **T                       =       i_mZ(RCA,RCA);

double **EigsValue               =       i_mZ(RCA,RCA);
double **EigsValue_cosh2a         =       i_mZ(RCA,RCA);
double **EigsValue_TwocoshAP2mns1 =       i_mZ(RCA,RCA);

double **cosh2a                   =       i_mZ(RCA,RCA);
double **TwocoshAP2mns1           =       i_mZ(RCA,RCA);

  clrscrn();
  printf(" A :");
  p_mZ(A, S9,P4, S8,P4, C3);

  printf(" V :");
  eigs_V_mZ(A,V,FACTOR_E);
  pE_mZ(V, S12,P4, S12,P4, C3);
  
  printf(" inv(V) ... Some time the matrix is not invertible :");
  inv_mZ(V,invV);
  pE_mZ(invV, S12,P4, S12,P4, C3);
  
  printf(" EigsValue = invV * A * V");
  mul_mZ(invV,A,T);
  mul_mZ(T,V,EigsValue); 
  pE_mZ(clean_eyes_mZ(EigsValue), S12,P4, S12,P4, C3);
  stop();

  clrscrn();  
  printf(" cosh(2*A)        :");
  EigsValue_cosh2A_mZ(EigsValue,EigsValue_cosh2a);
   
  mul_mZ(V,EigsValue_cosh2a,T);
  mul_mZ(T,invV,cosh2a); 
  pE_mZ(cosh2a, S12,P4, S8,P4, C3);

  printf(" 2cosh(A)**2-1 :");
  EigsValue_TwocoshAP2mns1_mZ(EigsValue,EigsValue_TwocoshAP2mns1);
   
  mul_mZ(V,EigsValue_TwocoshAP2mns1,T);
  mul_mZ(T,invV,TwocoshAP2mns1); 
  pE_mZ(TwocoshAP2mns1, S12,P4, S8,P4, C3);  
  
  f_mZ(A);
  
  f_mZ(V);  
  f_mZ(invV);  
  f_mZ(T);  
  
  f_mZ(EigsValue);
  
  f_mZ(EigsValue_cosh2a);   
  f_mZ(cosh2a); 
  
  f_mZ(EigsValue_TwocoshAP2mns1);   
  f_mZ(TwocoshAP2mns1);     
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
    fun();
    
} while(stop_w());

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


Exemple de sortie écran :
 A :
  +0.0372 +0.0710i   +0.0626 -0.0533i   -0.0692 +0.0382i 
  +0.0323 -0.0141i   -0.0083 +0.0192i   +0.0583 +0.0390i 
  -0.0879 +0.0934i   +0.0756 +0.0769i   -0.0965 -0.0218i 

 V :
 +3.7644e-01 -3.8849e-01i  -3.3837e-01 -3.8622e-01i  -5.6069e-01 -5.0586e-01i 
 -4.1615e-01 -9.1842e-02i  +5.0344e-01 +9.1015e-02i  -1.3652e-01 +3.9308e-01i 
 +7.2509e-01 +0.0000e+00i  +6.8892e-01 +3.8243e-17i  +5.0654e-01 +0.0000e+00i 

 inv(V) ... Some time the matrix is not invertible :
 +7.6906e-01 -5.6442e-01i  -5.1432e-01 -3.2041e-01i  +1.0277e+00 +4.5603e-01i 
 +3.0304e-01 +7.4472e-01i  +1.3937e+00 +3.0602e-01i  +2.0482e-01 +1.2790e-01i 
 -1.5130e+00 -2.0492e-01i  -1.1593e+00 +4.2449e-02i  +2.2455e-01 -8.2673e-01i 

 EigsValue = invV * A * V
 -1.2574e-01 +2.0074e-02i  +0.0000e+00 +0.0000e+00i  +0.0000e+00 +0.0000e+00i 
 +0.0000e+00 +0.0000e+00i  +4.4121e-02 +4.7789e-02i  +0.0000e+00 +0.0000e+00i 
 +0.0000e+00 +0.0000e+00i  +0.0000e+00 +0.0000e+00i  +1.4021e-02 +5.3752e-04i 

 Press return to continue. 


 cosh(2*A)        :
 +1.0002e+00-1.4361e-02i  -3.1384e-03+3.3977e-03i  +1.5961e-02-1.2761e-02i 
 -1.3160e-02+9.1032e-03i  +1.0048e+00+9.0191e-03i  -1.5495e-02-4.0596e-03i 
 +8.3216e-03-1.7013e-02i  -1.6582e-02+4.5541e-03i  +1.0257e+00+3.6040e-03i 

 2cosh(A)**2-1 :
 +1.0002e+00-1.4361e-02i  -3.1384e-03+3.3977e-03i  +1.5961e-02-1.2761e-02i 
 -1.3160e-02+9.1032e-03i  +1.0048e+00+9.0191e-03i  -1.5495e-02-4.0596e-03i 
 +8.3216e-03-1.7013e-02i  -1.6582e-02+4.5541e-03i  +1.0257e+00+3.6040e-03i 


 Press   return to continue
 Press X return to stop