/*
2 3 4
-3 3 1
*/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 1000;
typedef double Matrix[maxn][maxn];
void gauss_elimination(Matrix A, int n) {
int i, j, k, r;
for(i = 0; i < n; i++) {
r = i;
for(j = i+1; j < n; j++)
if(fabs(A[j][i]) > fabs(A[r][i])) r = j;
if(r != i)
for(j = 0; j <= n; j++)
swap(A[r][j], A[i][j]);
for(k = i+1; k < n; k++) { //消去第k行
double f = A[k][i] / A[i][i];
//为了让A[k][i] = 0, 第i行所乘以的倍数
for(j = i; j <= n; j++) A[k][j] -= f*A[i][j];
//这样就可以消掉i+1行到n行的第j个系数
}
}
//回代过程666模拟的很好
for(i = n-1; i >= 0; i--) {
for(j = i+1; j < n; j++)
A[i][n] -= A[j][n] * A[i][j];
A[i][n] /= A[i][i];
}
}
//这个函数运行结束后A[i][n]是第i个未知数的值
int main() {
int N;
cin >> n;
return 0;
}
高斯消元法求矩阵系数
最新推荐文章于 2022-04-08 09:19:05 发布