J'essayais de calculer le déterminant d'une matrice 3 * 3 (ou plus) avec les valeurs de la matrice allant de (-1, à 1). Cependant, j'obtiens un résultat de 0 quand je calcule le déterminant.Calcul du déterminant en C++
[...]
srand(time(NULL));
//Random generation of values between -1 and 1
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
temp = (rand() % (500)) + 0;
temp = temp/250;
array[i][j] = (temp - 1);
}
[...]
double array2[10][10];
double detrm = 0;
int s = 1;
int i, j, m, n, c;
for (c = 0; c < x; c++)
{
m = 0;
n = 0;
for (i = 0; i < x; i++)
{
for (j = 0; j < x; j++)
{
array2[i][j] = 0;
if (i != 0 && j != c)
{
array2[m][n] = a[i][j];
if (n < (x - 2))
{
n++;
}
else
{
n = 0;
m++;
}
}
}
}
detrm = detrm + (s*a[0][c]*determinant(array2, (x - 1)));
s = -1*s;
}
return(detrm);
La matrice est-elle singulière? Vous n'avez jamais initialisé 'array2', il est donc très possible que le junk qu'il contient soit singulier. – Mysticial
la matrice n'est pas au singulier – Josh
Avez-vous essayé d'imprimer la matrice et de l'exécuter dans une implémentation fonctionnelle? – Mysticial