Детриминант Матрицы n x n

Кто может сказать мне мою ошибку?

Определитель не является правильным!

Я сделал тест на листе бумаги, и ответ правильный!

Я считаю, что, возможно, моя ошибка в то же время, в строке «Matriz [i + 1] [j] = (Matriz [i + 1] [j] — (Matriz [fila] [j] * (Matriz [i +] 1] [0] / Matriz [fila] [fila]))); «но мой тест правильный.

#include <iostream>
#include <stdio.h>

using namespace std;

class Matriznxm{

private:

int n,m;
float **Matriz;

public:Matriznxm(int f, int c){

n = f;
m = c;
Matriz = new float *[n];

for (int i=0; i<n; i++){

Matriz[i]=new float [m];
}

for(int i=0; i<n; i++){

for(int j=0; j<m; j++ ){

Matriz[i][j]=0.0;

}

}
}void llenarMatriz(){

for(int i=0; i<n; i++){

for(int j=0; j<m; j++){

cout << "\nMatriz ["<<i+1<<"]["<<j+1<<"]: ";
cin >> Matriz[i][j];

}

}

}

void mostrarMatriz(){

for(int i=0; i<n; i++){for(int j=0; j<m; j++){cout << Matriz[i][j]<< "  ";

}
cout << "\n";
}

}int determinante(){

float det = 1.0;
int fila = 0;while(fila < n-1){

for(int i=fila; i<n-1; i++){

for(int j=fila; j<m; j++){Matriz[i+1][j] = (Matriz[i+1][j] - (Matriz[fila][j]*(Matriz[i+1][0]/Matriz[fila][fila])));

}

}fila++;

}for (int i=0; i<n; i++){

det= det * Matriz[i][i];

}return det;
}

};

int main () {

int n,m;

cout<<"\nNumero de Filas y Columnas: ";
cin >> n;
cout << "\n\n\n";
m=n;

Matriznxm m1(n,m);

m1.llenarMatriz();
m1.mostrarMatriz();

cout << "\nEl determinante es: "<< m1.determinante() <<"\n\n";
m1.mostrarMatriz();return 1;

}

0

Решение

#include <iostream>
using namespace std;
int main()
{
int siz;
cout<< "enter the size of you matrix AxA\nA = ";
cin >>siz;
int mat[siz][siz],rez=0,rezA=1,rezB=1;
for(int i=0;i<siz;i++)
for(int j=0;j<siz;j++)
cin >> mat[i][j];
for(int t=0;t<siz;t++){
for(int i=0;i<siz;i++)
{
rezA = rezA *mat[i][i+t>siz-1?(i+t-siz):i+t];
rezB = rezB *mat[i][siz-t-1-i<0?(2*siz-t-1-i):(siz-t-1-i)];
}
rez  = rez + (rezA - rezB);
rezA =rezB = 1;
}
cout <<endl<<"The Determinat is : "<<rez;
return 0;
}
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector