Subscribe Us

Responsive Advertisement

Advertisement

3. Newton rapshon method

 3. Newton rapshon method



//equation x^3-x-1

#include<bits/stdc++.h>

using namespace std;

#define maxval 1000000

double f(double x)

{

   return x*x*x - x - 1;

}

double df(double x)

{


    return 3*x*x-1;

}

void rapshon(double a)

{

    double erro=f(a)/df(a);

    while(abs(erro)>.001)

    {

        erro=f(a)/df(a);

        a=a-erro;

    }

    cout<<"Root : "<<a<<endl;

}

int main()

{


    cout<<"Enter value : ";

    double x,y;

    cin>>x;

    rapshon(x);

    return 0;

}


Post a Comment

0 Comments