Untitled

 avatar
unknown
plain_text
9 months ago
611 B
7
Indexable
#include <iostream>
#include <cmath>

#define EPSILON 0.001

using namespace std;

double func(double x)
{
    return exp(x * sin(x)) - 1;
}

double derivFunc(double x)
{
    return exp(x*sin(x)) * (sin(x) + x*cos(x));
}


void newtonRaphson(double x)
{
    double h = func(x) / derivFunc(x);
    while (abs(h) >= EPSILON)
    {
        h = func(x) / derivFunc(x);
        x = x - h;
    }

    cout << "The value of the root is : " << x << endl;
}

int main()
{
    double x0;
    cout << "Enter the initial value: ";
    cin >> x0;
    newtonRaphson(x0);
    return 0;
}
Editor is loading...
Leave a Comment