#include<iostream>
#include<cmath>
using namespace std;
double f(double x);
double f1(double x);
double f2(double x);
int main()
{
double x0, x1,e;
e = 0.0001; //终止门限
x0 = 15; //起始点
while (1)
{
x1 = x0 - (f1(x0) / f2(x0));
if (fabs(x1 - x0) < e)
{
cout<< x1<< ' ' << f(x1) <<endl;
break;
}
x0 = x1;
}
return 0;
}
double f(double x)
{
return (pow(x, 4) - 5 * pow(x, 3) + 4 * pow(x, 2) - 6 * x + 60+sin(x) );
}
double f1(double x)
{
return (4*pow(x, 3) - 15 * pow(x, 2) + 8*x - 6+cos(x) );
}double f2(double x)
{
return (12 * pow(x, 2) - 30 * x + 8-sin(x));
}
数学建模三 单变量优化和求解 牛顿迭代法
最新推荐文章于 2021-02-20 22:06:35 发布