高斯消去法
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
typedef vector<vector<double>> Matrix;
void dispMatrix(Matrix m);
void dispRes(vector<double> r);
int MajorRow(Matrix &m, int i);
double det(Matrix m);
void normlize(Matrix &m, int i);
vector<double> Gauss(Matrix &m);
int main()
{
ios::sync_with_stdio("false");
int n;
cin >> n;
Matrix M1(n, vector<double>(n + 1, 0));
for (int i = 0; i < n; i++)
for (int j = 0; j < n + 1; j++)
cin >> M1[i][j];
cout << det(M1) << endl;
vector<double> res = Gauss(M1);
dispRes(res);
system("pause");
return 0;
}
void dispMatrix(Matrix m)
{
cout << "Matrix:\n";
for (auto i : m)
{
for (auto ele : i)
cout << ele << " ";
cout << endl;
}
}
void dispRes(vector<double> r)
{
cout << "res:\n";
for (auto ele : r)
cout << ele << " ";
cout << endl;
}
int MajorRow(Matrix &m, int i)
{
int n = (int)m.size();
double max = 0;
int j, row;
for (row = i; row < n; row++)
if (fabs(m[row][i]) > max)
{