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 **EV_cos2A_mZ(
double **EV,
double **EV_cos2A
)
{
int  r;
int  c;

nb_Z cos2A;

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

        if(((r-R1)*C2)==c-C1)
          {
           cos2A = cos_Z(i_Z(2.*EV[r][c],2.*EV[r][c+C1]));
           
           EV_cos2A[r][c   ] = cos2A.r;
           EV_cos2A[r][c+C1] = cos2A.i;
          }
              
 return(EV_cos2A);
}
/* ------------------------------------ */
/* ------------------------------------ */
double **EV_TwocosA_2mns1_mZ(
double **EV,
double **EV_TwocosA_2mns1
)
{
int  r;
int  c;

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

nb_Z TwocosA_2mns1;

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

        if(((r-R1)*C2)==c-C1)
          {
                    cosa = cos_Z(i_Z( EV[r][c], EV[r][c+C1]));
           TwocosA_2mns1 = sub_Z(smul_Z(2., mul_Z(cosa,cosa)),mns1); 
           
           EV_TwocosA_2mns1[r][c   ] = TwocosA_2mns1.r;
           EV_TwocosA_2mns1[r][c+C1] = TwocosA_2mns1.i;
          }
              
 return(EV_TwocosA_2mns1);
}
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
{                               
double **A                       = i_mZ(RCA,RCA);

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

double **EV               = i_mZ(RCA,RCA);
double **EV_cos2a         = i_mZ(RCA,RCA);
double **EV_TwocosA_2mns1 = i_mZ(RCA,RCA);

double **cos2a                   =       i_mZ(RCA,RCA);
double **TwocosA_2mns1           =       i_mZ(RCA,RCA);

   do
  {
       rE_mZ(A,999,+1.E-4);  
   eigs_V_mZ(A,V,FACTOR_E);
  }while(!det_Z(V).r);
  
  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(" EV = invV * A * V");
  mul_mZ(invV,A,T);
  mul_mZ(T,V,EV); 
  pE_mZ(clean_eyes_mZ(EV), S12,P4, S12,P4, C3);
  stop();

  clrscrn();  
  printf(" cos(2*A)        :");
  EV_cos2A_mZ(EV,EV_cos2a);
   
  mul_mZ(V,EV_cos2a,T);
  mul_mZ(T,invV,cos2a); 
  pE_mZ(cos2a, S12,P4, S8,P4, C3);

  printf(" 2cos(A)**2-1 :");
  EV_TwocosA_2mns1_mZ(EV,EV_TwocosA_2mns1);
   
  mul_mZ(V,EV_TwocosA_2mns1,T);
  mul_mZ(T,invV,TwocosA_2mns1); 
  pE_mZ(TwocosA_2mns1, S12,P4, S8,P4, C3);  
  
  f_mZ(A);
  
  f_mZ(V);  
  f_mZ(invV);  
  f_mZ(T);  
  
  f_mZ(EV);
  
  f_mZ(EV_cos2a);   
  f_mZ(cos2a); 
  
  f_mZ(EV_TwocosA_2mns1);   
  f_mZ(TwocosA_2mns1);     
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

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

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


Exemple de sortie écran :
 A :
  -0.0053 +0.0436i   -0.0152 -0.0318i   +0.0868 -0.0825i 
  -0.0896 -0.0125i   -0.0159 -0.0123i   +0.0366 +0.0760i 
  +0.0824 -0.0465i   +0.0151 -0.0321i   -0.0527 +0.0088i 

 V :
 -4.3960e-01 +2.3951e-01i  +6.8694e-01 +6.4846e-02i  +3.0583e-01 +2.1385e-01i 
 -2.3624e-01 -5.0902e-01i  -4.6066e-01 +2.7664e-01i  +1.1715e-01 -8.2464e-01i 
 +6.5914e-01 +9.1475e-18i  +4.8495e-01 +2.6920e-17i  +4.0864e-01 +0.0000e+00i 

 inv(V) ... Some time the matrix is not invertible :
 -8.6780e-01 -9.9173e-03i  -1.9196e-01 -1.3377e-01i  +9.6926e-01 +1.1252e-01i 
 +5.7631e-01 +2.5119e-02i  -1.8518e-01 -5.5564e-01i  +7.5620e-01 -5.3481e-01i 
 +7.1584e-01 -1.3813e-02i  +5.2941e-01 +8.7518e-01i  -1.3712e-02 +4.5318e-01i 

 EigsValue = invV * A * V
 -1.2096e-01 +6.9597e-02i  +0.0000e+00 +0.0000e+00i  +0.0000e+00 +0.0000e+00i 
 +0.0000e+00 +0.0000e+00i  +7.4206e-02 -6.9435e-03i  +0.0000e+00 +0.0000e+00i 
 +0.0000e+00 +0.0000e+00i  +0.0000e+00 +0.0000e+00i  -2.7146e-02 -2.2554e-02i 

 Press return to continue. 


 cos(2*A)        :
 +9.9510e-01+1.6453e-02i  +2.3495e-05+7.6329e-03i  -2.1934e-03-1.3962e-02i 
 -1.7612e-02-4.1358e-03i  +9.9192e-01-6.8147e-03i  +2.2013e-02-1.8179e-03i 
 +8.2685e-03-1.9280e-02i  +7.7511e-03-4.3735e-04i  +9.8193e-01+2.3420e-02i 

 2cos(A)**2-1 :
 +9.9510e-01+1.6453e-02i  +2.3495e-05+7.6329e-03i  -2.1934e-03-1.3962e-02i 
 -1.7612e-02-4.1358e-03i  +9.9192e-01-6.8147e-03i  +2.2013e-02-1.8179e-03i 
 +8.2685e-03-1.9280e-02i  +7.7511e-03-4.3735e-04i  +9.8193e-01+2.3420e-02i 


 Press   return to continue
 Press X return to stop