用戶將輸入2個方程,然後解決它的迭代(抱歉我的英語)。循環未被執行的問題。當et的值小於g的值時,代碼應該突然出現。任何人都可以幫助我循環我的程序(GAUSS SEIDEL METHOD)嗎?
代碼:
#include <iostream>
#include<stdlib.h>
using namespace std;
long double g=0.0010;
int main()
{
long double xe,ye,et,k,x,y,x1,x2,y1,y2,c1,c2,a,b;
//for the input
cout<<"EQUATION 1:\n";
cout<<"Input your desired numerical coefficient for x:"<<endl;
cin>>x1;
cout<<"Input your desired numerical coefficient for y:"<<endl;
cin>>y1;
cout<< "Input your constant's value:"<<endl;
cin>>c1;
system("CLS");
cout<<"EQUATION 2:\n";
cout<<"Input your desired numerical coefficient for x:"<<endl;
cin>>x2;
cout<<"Input your desired numerical coefficient for y:"<<endl;
cin>>y2;
cout<< "Input your constant's value:"<<endl;
cin>>c2;
system("CLS");
//to show the equation made
cout<<"Your EQUATION 1 is:\n"<<x1<<"x + <"<<y1<<"y)"<<" = "<<c1<<endl<<endl;
cout<<"Your EQUATION 2 is:\n"<<x2<<"x + ("<<y2<<"y)"<<" = "<<c2<<endl<<endl;
//first value of x and y
x=c1/x1;
y=(c2)/y2;
//show the values
cout<<"\nx="<<x<<endl;
cout<<"y="<<y<<endl;
//this is where the iteration starts
for(k=1;g>et;k++)
{
a=(c1+y)/x1;
b=(c2-x)/y2;
xe=((a-y)/a)*-1;
ye=((b-x)/b);
et=((xe+ye)/2);
cout<<"k="<<k;
cout<<"\nx="<<a<<endl;
cout<<"y="<<b<<endl;
cout<<"\nxe="<<xe;
cout<<"\nye="<<ye;
cout<<"\net="<<et<<endl;
}
return 0;
}
et應該是xe和ye的平均值。 – 2012-03-18 06:48:45
@BossJeric我誤解了變量......請使用更多的空格和註釋。這個答案是更新的,現在應該是有見地的。 – Potatoswatter 2012-03-18 06:56:34
好吧,我會嘗試提出一些意見。 – 2012-03-18 07:00:18