Subscribe Us

Responsive Advertisement

Advertisement

4. Iteration method using c++

 


4. Iteration method using c++


//equation x^3-x-1

#include<bits/stdc++.h>

#define val (double).0001

using namespace std;


double f(double x)

{

    return (3*x-1)/(x*x);

}


void iteration(double x)

{

    double root;

    root=x;

   while(1)

    {

        root=f(x);

        //cout<<root<<endl;

        if(abs(root-x)<=val)

        {

            break;

        }

        x=root;

    }

    cout<<"Root is : "<<root<<endl;

}

int main()

{


    iteration(3.2);



    return 0;

}


Post a Comment

0 Comments