数值方法牛顿法解非线性方程

解非线性方程y=x^3 +4*x^2-10在区间[1,2]的根,精确到小数点后第三位
hanshu为迭代公式

#include <iostream>
using namespace std;
#define WUCHA 0.0005
double hanshu(double x) {
    return x - (x * x * x + 4 * x * x - 10) / (3 * x * x + 8 * x);
}
int main()
{
    double x = 1.5;
    double xx = 100000;
    int count = 0;
    while (abs(x-xx)>WUCHA) {
        xx = x;
        x = hanshu(x);
        count++;
        
    }
    cout << "结果:" << x << endl;
    cout << "迭代次数:" << count;
}

在这里插入图片描述

发布了4 篇原创文章 · 获赞 0 · 访问量 121

猜你喜欢

转载自blog.csdn.net/weixin_43625164/article/details/104617434