Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
632 B
0
Indexable
Never
#include<iostream>
#include<cmath>
using namespace std;

float eqn(float x)
{
    return ((x*x*x)-x-4);
}

float  bisect(float a, float b)
{
    float fa=a;
    float fb =b;
    float fx;

    while(fabs(fa-fb)>= 0.0001)
    {
        float c= (fa+fb)/2;
        float fx= eqn(c);
        cout<<"The iterative value is "<<fx<<"\n";
        
        if(fx>0)
        {
            fb=c;
        }
        else if(fx<0)
        {
            fa=c;
        }
    }
return fx;
}


int main()
{
float a=1;
float b= 2;

float val= bisect(a,b);
cout<<"the root value ="<<val;



    return 0;
}
Leave a Comment