typedef double **matrice;
#define N 3
void al_prod_mat_vect (matrice const mat, double const *x, double **py)
{
double *y = malloc (N * sizeof *y);
if (y != NULL)
{
int i;
for (i = 0; i < N; i++)
{
y[i] = 0;
}
for (i = 0; i < N; i++)
{
int j;
for (j = 0; j < N; j++)
{
y[i] = y[i] + mat[i][j] * x[j];
}
}
if (py != NULL)
{
*py = y;
}
}
}
int main (void)
{
double *x = malloc (sizeof *x * N);
if (x != NULL)
{
x[0] = 2;
x[1] = 2;
x[2] = 9;
{
matrice mat = malloc (sizeof *mat * N);
if (mat != NULL)
{
int err;
int i;
for (i = 0; i < N; i++)
{
mat[i] = malloc (sizeof *mat[i] * N);
err = mat[i] == NULL;
}
if (!err)
{
mat[0][0] = 4;
mat[0][1] = 0;
mat[0][2] = 0;
mat[1][0] = 0;
mat[1][1] = 1;
mat[1][2] = 0;
mat[2][0] = 0;
mat[2][1] = 0;
mat[2][2] = 2;
{
double *y;
al_prod_mat_vect (mat, x, &y);
if (y != NULL)
{
printf ("les coordonnees de l'image sont (%.2f, %.2f, %.2f)\n"
, y[0]
, y[1]
, y[2]);
free (y), y = NULL;
}
}
}
for (i = 0; i < N; i++)
{
free (mat[i]), mat[i] = NULL;
}
free (mat), mat = NULL;
}
}
free (x), x = NULL;
}
return 0;
}
|