我正在尝试执行求解线性系统 A*x = b 的函数,其中 A = 下三角矩阵、线性独立矩阵并且只有一个解。 但是结果总是显示 0 0 0 0 ... 我已经打印了总和,s,它也总是显示 0...
#include <iostream>
using namespace std;
void solve(int n, float a[][MAX], float b[], float x[]){
int i,j;
float s;
for(i = 0; i < n; i++){
s = 0;
for(j = 0; j < n; j++){
s = s + a[i][j]*x[j];
cout<<s<<endl;
}
x[i] = (b[i] - s)/a[i][i];
}
}
最佳答案
void solve(int n, float a[][MAX], float b[], float x[]){
int i,j;
float s;
for(i = 0; i < n; i++) {
s = 0;
for(j = 0; j < i; j++) {
^
s = s + a[ i][ j] * x[ j];
}
x[ i] = ( b[ i] - s) / a[ i][ i];
}
}
关于c++ - 在 C++ 中求解 Ax = b, A = 下三角矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22237322/