Mathc complexes/00b
Apparence
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_cos2A_mZ(
double **EigsValue,
double **EigsValue_cos2A
)
{
int r;
int c;
nb_Z cos2A;
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)
{
cos2A = cos_Z(i_Z(2.*EigsValue[r][c],2.*EigsValue[r][c+C1]));
EigsValue_cos2A[r][c ] = cos2A.r;
EigsValue_cos2A[r][c+C1] = cos2A.i;
}
return(EigsValue_cos2A);
}
/* ------------------------------------ */
/* ------------------------------------ */
double **EigsValue_TwocosA_2mns1_mZ(
double **EigsValue,
double **EigsValue_TwocosA_2mns1
)
{
int r;
int c;
nb_Z cosa;
nb_Z mns1 = {1,0};
nb_Z TwocosA_2mns1;
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)
{
cosa = cos_Z(i_Z( EigsValue[r][c], EigsValue[r][c+C1]));
TwocosA_2mns1 = sub_Z(smul_Z(2., mul_Z(cosa,cosa)),mns1);
EigsValue_TwocosA_2mns1[r][c ] = TwocosA_2mns1.r;
EigsValue_TwocosA_2mns1[r][c+C1] = TwocosA_2mns1.i;
}
return(EigsValue_TwocosA_2mns1);
}
/* ------------------------------------ */
/* ------------------------------------ */
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_cos2a = i_mZ(RCA,RCA);
double **EigsValue_TwocosA_2mns1 = i_mZ(RCA,RCA);
double **cos2a = i_mZ(RCA,RCA);
double **TwocosA_2mns1 = 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(" cos(2*A) :");
EigsValue_cos2A_mZ(EigsValue,EigsValue_cos2a);
mul_mZ(V,EigsValue_cos2a,T);
mul_mZ(T,invV,cos2a);
pE_mZ(cos2a, S12,P4, S8,P4, C3);
printf(" 2cos(A)**2-1 :");
EigsValue_TwocosA_2mns1_mZ(EigsValue,EigsValue_TwocosA_2mns1);
mul_mZ(V,EigsValue_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(EigsValue);
f_mZ(EigsValue_cos2a);
f_mZ(cos2a);
f_mZ(EigsValue_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.0286 +0.0042i +0.0972 -0.0061i -0.0644 -0.0826i
-0.0828 -0.0373i +0.0421 -0.0110i +0.0196 -0.0747i
-0.0084 +0.0238i +0.0388 -0.0965i +0.0181 +0.0877i
V :
-2.3663e-01 +6.0160e-01i +5.5634e-01 +1.8075e-01i -2.3395e-01 -6.3154e-01i
-5.1858e-01 -4.0518e-02i +7.1303e-01 -1.8652e-01i +3.6970e-01 -5.7834e-02i
+5.5813e-01 +0.0000e+00i +3.3853e-01 +2.0004e-17i +6.3749e-01 +0.0000e+00i
inv(V) ... Some time the matrix is not invertible :
+1.3849e-01 -4.0216e-01i -6.4362e-01 +1.9729e-01i +8.0459e-01 -1.8320e-01i
+3.8167e-01 -5.4317e-01i +7.2350e-01 +5.5237e-01i +2.0847e-01 -7.5935e-02i
-3.2393e-01 +6.4054e-01i +1.7929e-01 -4.6606e-01i +7.5351e-01 +2.0072e-01i
EigsValue = invV * A * V
-4.7048e-02 +1.5540e-01i +0.0000e+00 +0.0000e+00i +0.0000e+00 +0.0000e+00i
+0.0000e+00 +0.0000e+00i +2.0141e-02 -1.0230e-01i +0.0000e+00 +0.0000e+00i
+0.0000e+00 +0.0000e+00i +0.0000e+00 +0.0000e+00i +5.8507e-02 +2.7804e-02i
Press return to continue.
cos(2*A) :
+1.0099e+00+8.5302e-03i +1.8584e-02-4.5581e-03i -1.9660e-02+2.4930e-02i
-5.5410e-04-2.3265e-03i +1.0263e+00+1.7856e-02i -1.8412e-02-1.2661e-02i
+1.7946e-02-1.1055e-02i -1.8237e-02+8.2896e-04i +1.0227e+00+5.0901e-03i
2cos(A)**2-1 :
+1.0099e+00+8.5302e-03i +1.8584e-02-4.5581e-03i -1.9660e-02+2.4930e-02i
-5.5410e-04-2.3265e-03i +1.0263e+00+1.7856e-02i -1.8412e-02-1.2661e-02i
+1.7946e-02-1.1055e-02i -1.8237e-02+8.2896e-04i +1.0227e+00+5.0901e-03i
Press return to continue
Press X return to stop