#include
#include
#include
#include "fstream"
#define esp 0.5e-8
using namespace std;
class SLACK
{
private:
int time; //迭代次数
double left; //迭代初值
double right;
int flag;
public:
double aa[2][20]; //用于存放每次迭代的xk;
double bb[2][20]; //用于存放每次迭代的误差 f;
double fun(double xk); // 需要迭代的函数
double Itformat(double xk); //函数的迭代格式
void getvalue(); //从文本中读值
double slack(); //计算
void show(); //输出
double fun1(double xk);
};
double SLACK::fun(double xk)
{
double f;
f = xk*xk*xk*xk-4*xk*xk+4;
return f;
}
double SLACK::fun1(double xk)
{
double f;
f = 4*xk*xk*xk-8*xk;
return f;
}
double SLACK::Itformat(double xk)//
{
double x1;
x1=xk-1.0*fun(xk)/fun1(xk);
return (x1);
}
void SLACK::getvalue()
{
double a[3];
ifstream infile("in.txt",ios::in);
if(!infile)
{
cerr<<"In file open error!"<<endl;
exit(1);
}
for(int i=0;i<3;i++)
infile>>a[i];
牛顿迭代法求方程解(单重根情形) c++
最新推荐文章于 2023-01-08 22:49:24 发布