#include
#include
#include
#include "fstream"
#define esp 0.5e-8
using namespace std;
class SLACK
{
private:
int time; //迭代次数
double svalue; //迭代初值
public:
double aa[20]; //用于存放每次迭代的xk;
double bb[20]; //用于存放每次迭代的误差 f;
double fun(double xk); // 需要迭代的函数
double Itformat(double xk); //函数的迭代格式
void getvalue(); //从文本中读值
double slack(); //计算
void show(); //输出
};
double SLACK::fun(double xk)
{
double f;
f=(xk*xk-2*log(xk)-5);
return f;
}
double SLACK::Itformat(double xk)
{
xk=-xk/(xk*sqrt(2*log(xk)+5)-1)+xk*(2*log(xk)+5)/(xk*sqrt(2*log(xk)+5)-1);
return xk;
}
void SLACK::getvalue()
{
double a[2];
ifstream infile("in.txt",ios::in);
if(!infile)
{
cerr<<"In file open error!"<<endl;
exit(1);
}
for(int i=0;i<2;i++)
infile>>a[i];
SLACK::svalue=a[0];
SLACK::time=a[1];
infile.close();
}
double SLACK::slack()
{
松弛迭代法求根C++语言
最新推荐文章于 2024-05-10 17:46:30 发布