Numerical method Newton's second derivative method for solving nonlinear equations

Solve the nonlinear equation y = x ^ 3 + 4 * x ^ 2-10 at the root of the interval [1,2], accurate to the third decimal place
hanshu is the iterative formula

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

Insert picture description here

Published 30 original articles · won 9 · visited 1330

Guess you like

Origin blog.csdn.net/weixin_43625164/article/details/104617822