### bisection and secant method

i am needing to implement the bisection and the secant method of solving for the roots of multiple equations and i am struggling on how to do it. here is what i have so far. any help would be greatly appreciated. thanks.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192`` ``````#include #include #include #include #include #include using namespace std; double RootMethod1(double fx1, double E, double I, double x1, double x2, double root1 ); double RootMethod2(double fx1, double E, double I, double x1, double x2, double root2 ); int main() { int choice; double x, x1, x2, x3, I, E, fx1, root1, root2; ofstream outfile; outfile.open("RootMethod1.txt"); outfile.open("RootMethod2.txt"); cout << "this is a root finding program" << endl; cout << "which equation would you like to solve for ?" << endl; cout << "1 : f(x)=2x-2" << endl; cout << "2 : x^2-2x+2" << endl; cout << "3 : e^(-1.4x)sin(2x)" << endl; cout << "4 : x^4-10x^3-2x+3" << endl; cin >> choice; cout << "what is your low x guess?" <> x1; cout << "what is your high x guess?" <> x2; cout << "how many iterations do you want?" <> I; cout << "how close do you want the estimate (Epsilon)?" <> E; switch (choice){ case 1: fx1 = 2*x-2; root1 = RootMethod1 ( fx1, E, I, x1, x2, root1 ); root2 = RootMethod2 ( fx1, E, I, x1, x2, root2 ); break; case 2: fx1 = x*x-2*x+2; root1 = RootMethod1 (fx1, E, I, x1, x2, root1 ); root2 = RootMethod2 ( fx1, E, I, x1, x2, root2 ); break; case 3: fx1 = pow( 10, -1.4*x)*sin(2*x); root1 = RootMethod1 (fx1, E, I, x1, x2, root1); root2 = RootMethod2 ( fx1, E, I, x1, x2, root2 ); break; case 4: fx1 = (pow(x,4)-pow(10*x,3)-2*x+3); root1 = RootMethod1 (fx1, E, I, x1, x2, root1); root2 = RootMethod2 ( fx1, E, I, x1, x2, root2 ); break; } cout << "your root is "<< x3 << endl; outfile.close(); outfile.close(); cout<
Last edited on
Topic archived. No new replies allowed.