#include #include #include #include #include "fonctions_tableaux.h" #include "boulanger.h" #define dimension 2000 #define nombreRectangles 5 #define lvdl 1 #define lvdr 1 void zgeev_(char*,char*, // JOBVL and JOBVR int*, // Matrix Size double complex[], // matrix int*, // leading dimension of the matrix double complex[], // Eigenvalues array double complex[], // VL contient les vecteurs propres à gauche, dim(LDVL, N) int*, // LDVL >=1 si JOBVL = 'N', >=N si JOBVL = 'V' double complex[], // VR contient les vecteurs propres à gauche, dim(LDVR, N) int*, // LDVL >=1 si JOBVL = 'N', >=N si JOBVL = 'V' double complex[], // WORK espace de travail int*, // LWORK : taille de WORK double[], // RWORK espace de travail, dimension 2N int* // INFO ); int main (void){ int i = 0, j = 0 , LWORK = 64 * dimension, ifail = 0 , nombreMatrice = dimension , LVDL = lvdl , LVDR = lvdr; double complex **matrice = malloc(dimension * sizeof(double complex)); for (i = 0; i < dimension; i++) { matrice[i] = malloc(dimension * sizeof(double complex)); } int largeursBlocs[nombreRectangles] = {100, 850, 100, 850, 100}; //il faut que la somme des constituants de ce tableau soit égale à la dimension double trou[nombreRectangles] = {0, 1, 0, 1, 0}; FILE* valeursPropres = NULL; boulangerOuvertLisse(dimension, nombreRectangles, largeursBlocs, trou, matrice); for (i = 0 ; i < dimension ; i++) { for (j = 0 ; j < dimension ; j++) { printf("%d, %d, %.10f, %.10f \n",i, j, creal(matrice[i][j]), creal(matrice[i][j])); } } double complex *travail = malloc(dimension * dimension * sizeof(double complex)); // il faut allouer dynamiquement pour accéder à toute la mémoire for (i = 0 ; i < dimension ; i++) { for (j = 0 ; j < dimension ; j++) { travail[dimension * i + j] = matrice[i][j]; //printf("%d, %d \n", i, j); } } /*for (i = 0; i < dimension; i++) { free(matrice[i]); } free(matrice);*/ for (i = 0; i < dimension* dimension; i++) { printf("%d, %f, %f \n", i, creal(travail[i]), cimag(travail[i])); } /*for (i = 0; i < dimension; i++) { free(matrice[i]); } free(matrice);*/ char JOBVL = 'N' ; char JOBVR = 'N'; double complex *eigenvalues = malloc(dimension * sizeof(double complex)); double complex *VL = malloc(dimension * lvdl * sizeof(double complex)); double complex *VR = malloc(dimension * lvdr * sizeof(double complex)); double complex *WORK = malloc(LWORK * sizeof(double complex)); double *RWORK = malloc(2 * dimension * sizeof(double)); zgeev_(&JOBVL, &JOBVR, &nombreMatrice, travail, &nombreMatrice, eigenvalues, VL, &LVDL, VR, &LVDR, WORK, &LWORK, RWORK, &ifail) ; for (i = 0 ; i < dimension ; i++) { for (j = 0 ; j < dimension ; j++) { printf("%d, %d, %.10f, %.10f \n",i, j, creal(matrice[i][j]), creal(matrice[i][j])); } } free(travail); free(WORK); free(RWORK); free(VR); free(VL); printf("ifail : %d \n", ifail); printf("Voici les valeurs propres \n"); for (i = 0 ; i < dimension ; i++) { printf("%f, %f \n", creal(eigenvalues[i]), cimag(eigenvalues[i])); } printf("\n") ; /*for (i = 0; i < dimension; i++) { free(matrice[i]); } free(matrice);*/ valeursPropres = fopen("valeurs_propres.txt", "w"); if (valeursPropres != NULL) { for(i = 0 ; i < dimension ; i++) { fprintf(valeursPropres, "%f \t %f \t %f \t %f \n", creal(eigenvalues[i]), cimag(eigenvalues[i]), cabs(eigenvalues[i]), carg(eigenvalues[i])); } } else { printf("Impossible d'ouvrir le fichier valeurs_propres.txt"); } free(eigenvalues); fclose(valeursPropres); /*for (i = 0; i < dimension; i++) { free(matrice[i]); } free(matrice)*/; return 0; }