Mathc complexes/Fichiers h : vim2
Apparence
Installer ce fichier dans votre répertoire de travail.
wim2.h |
---|
/* ------------------------------------ */
/* Save as : wi_m2.h */
/* ------------------------------------ */
/* ---------------------------------------------------------------------------
Do : Dynamically allocate a multidimensional array.
(see : FAQ of the comp.lang.c group)
You can keep the array's contents contiguous,
r0 r1 r2 ... rn
R_000|C_xxx|0_xxx|...|0_xxx
R = Number of rows.
C = Number of columns.
The declaration of the sizes into the matrices, it is my work.
So be careful.
The first row and the first column are not used.
*********************
The size of the row of the matrix is into A[R_SIZE][C0] = A[0][0]
The size of the column of the matrix is into A[C_SIZE][C0] = A[1][0]
*********************
Complex Matrices
The first element of the matrix is z =(A[1][1*C2],A[1][1*C2+C1])
For a 10x10 matrix the last element is z = (A[10][10*C2],A[10][10*C2+C1])
*********************
If you want to duplicate a matrix A, you must use :
double **T;
T = i_duplicate_mZ( A[R_SIZE][C0],
A[C_SIZE][C0]);
f_mZ(T);
-------------------------------------------------------------------------- */
/* ------------------------------------ */
double **i_mZ(
int r,
int c
)
{
double **A;
int ar;
int ac;
int i;
if(r<R1||c<C1)
{
printf(" The size of the matrix must be positive integers.\n\n");
printf(" double **i_mR(); \n\n");
fflush(stdout);
getchar();
exit(EXIT_FAILURE);
}
ar = r + R1;
ac = c*C2 + C1;
A = malloc(ar * sizeof(**A));
if(!A)
{
printf(" I was unable to allocate the memory you requested.\n\n");
printf(" double **i_mR(); \n\n");
printf(" **A = malloc(ar * sizeof(*A));\n\n");
fflush(stdout);
getchar();
exit(EXIT_FAILURE);
}
A[0] = malloc(ar * ac * sizeof(**A) );
if(!A[0])
{
printf(" I was unable to allocate the memory you requested.\n\n");
printf(" double **i_mR();\n\n");
printf(" A[0] = malloc(ar * ac * sizeof(**A) );\n\n");
fflush(stdout);
getchar();
exit(EXIT_FAILURE);
}
for(i=1; i<ar; i++) A[i] = A[0]+i*ac;
/* ----------- Give a value to the zero row and the zero column ------------- */
A[R_SIZE][C0] = ar;
A[C_SIZE][C0] = ac;
for(r=R2; r<A[R_SIZE][C0]; r++)
A[r][C0] = 0.;
for(c=C1, i=1; c<A[C_SIZE][C0]; c+=C2, i++)
{
A[R0][c] = i;
A[R0][c+C1] = 0; }
m0_mZ(A);
return(A);
}
/* ------------------------------------ */
void f_mZ(
double **A
)
{
if(A) free(A[0]);
free(A);
}
/* ------------------------------------ */
double **i_RC_mZ(
int R,
int C
)
{
R = (R-R1);
C = ((C-C1)/C2);
return( i_mZ(R,C) );
}
/* ------------------------------------ */
/* ------------------------------------ */
C'est dans ce fichier que se trouvent les fonctions de constructions et de destructions des matrices. L'étude de ce code pourra se faire dans un deuxième temps.