您的位置:首页 > 其它

数学建模三 单变量优化和求解 牛顿迭代法

2017-04-20 14:17 281 查看
#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));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: