Hi.. I've been working on this bisection method program using some pseudocode of wikipedia, and I have gotten myself in a bind. The compiler tells me there is a syntax error with the last return in my program. I'll post it here. Any comments would be greatly appreciated.
Thanks,
Brian
ill highlight the error in red
Code:#include <iostream>
#include <math.h>
#include <iomanip>
#include <fstream>
using namespace std;
double mdpt (double a, double b)
{
double mdptfn = ((a + b) / 2);
return (mdptfn);
}
int main()
{
double a = 0;
double b = 2;
double precision;
cout << " Enter a precision "<<endl;
cin >> precision;
double Fa = pow(a,3) - (7 * pow(a,2)) + (5 * a) + 3;
double Fb = pow(b,3) - (7 * pow(b,2)) + (5 * b) + 3;
cout << Fa <<endl;
cout << Fb <<endl;
// begin the bisection loop
do while (abs(b - a) > precision)
{
// Find the Midpoint of the funtion
double midpoint = ((a + b) / 2);
cout << midpoint <<endl;
// find the answer for midpoint of the function
double Fofmid = pow(midpoint,3) - (7 * pow(midpoint,2)) + (5 * midpoint) + 3;
cout << Fofmid <<endl;
//determine the appropriate half to search in
if ((Fa * Fofmid) > 0)
double a = midpoint;
else
double b = midpoint;
}
return (mdpt (a,b));
}