Answer to Question #240814 in C++ for efly

Question #240814

Develop a program to find the roots of the quadratic equation using BISECTION METHOD.


1
Expert's answer
2021-09-22T23:43:38-0400
#include<iostream>
using namespace std;
#define EPSILON 0.01
 


double function(double y)
{
    return y*y*y - y*y + 2;
}
 
void bisectionMethod(double x, double y)
{
    if (function(x) * function(y) >= 0)
    {
        cout << "x and y are not right\n";
        return;
    }
 
    double root = x;
    while ((y-x) >= EPSILON)
    {
        
        root = (x+y)/2;
 
        
        if (function(root) == 0.0)
            break;
 
       
        else if (function(root)*function(x) < 0)
            y = root;
        else
            x = root;
    }
    cout << "The root value is: " << root;
}
 


int main()
{
   
    double x =-100, y = 600;
    bisectionMethod(x, y);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS