z2=a-bx2+cy2
z3=a-bx3+cy2
三元三次程求a,b,c
用C。或VB怎么编啊?(或别的语言)
帮帮忙啊!明天赶着用啊!谢谢了先!
#include <iostream> using namespace std;
void BGE (double a[100][100],double b[100],int n) { int pivo = 0; double temp; for (int i=1;i<=n;i++) a[i][n+1]=b[i]; for (i=1;i<=n-1;i++) { pivo = i; for (int j=i+1;j<=n;j++) if (abs(a[j][i])>abs(a[pivo][i])) pivo = j; for (int k=i;k<=n+1;k++) { temp = a[i][k]; a[i][k]=a[pivo][k]; a[pivo][k]=temp; } for (j=i+1;j<=n;j++) { temp = a[j][i]/a[i][i]; for (k=i;k<=n+1;k++) a[j][k]-=a[i][k]*temp; }
} }
void Answer(double a[100][100],double b[100],int n) { double temp; for(int i=n;i>=1;i--) { temp = a[i][n+1]; for (int j=n;j>i;j--) temp = temp - a[i][j]*b[j]; b[i] = temp/a[i][i]; } }
int main() { int n;int j; double a[100][100]; double b[100]; cout << "Please Input n: "; cin >> n; cout << endl; //input for (int i=1;i<=n;i++) for (j=1;j<=n;j++) { cout << "a[" << i << "][" << j << "]: "; cin >> a[i][j]; // cout << endl; } for (i=1;i<=n;i++) { cout << "b[" << i << "]: "; cin >> b[i]; // cout << endl; } //display input cout << "===============Ur Input=============" << endl; for (i=1;i<=n;i++) { for (j=1;j<=n;j++) cout << a[i][j] << "\t"; cout << b[i] << endl; } //Algroithm BetterGaussElimination BGE (a,b,n); //display BGE cout << "===============After BGE=============" << endl; for (i=1;i<=n;i++) { for (j=1;j<=n+1;j++) cout << a[i][j] << "\t"; cout << endl; } //display Answer Answer(a,b,n); cout << "===============ANSWER=============" << endl; for (i=1;i<=n;i++) cout << "x" << i << "=" << b[i] << endl; cin.get(); cin.get(); return 0; } 原则上不帮做作业 不过既然手里有 还是贴出来吧