main.cpp - Numerical Analysis Prof Fu HW2 due#include <iostream>#include <cmath>#include <iomanip> using namespace std int bisection(double a double b

# main.cpp - Numerical Analysis Prof Fu HW2 due#include...

• 3

This preview shows page 1 - 2 out of 3 pages.

// Numerical Analysis -- Prof. Fu // HW2 -- due: 09/13/2018 #include <iostream> #include <cmath> #include <iomanip> using namespace std; int bisection(double a, double b, double f_a, double e, double exact); int secant(double x_0, double x_1, double f_0, double f_1, double e, double exact); int newton(double x_0, double f_0, double e, double exact); //int modified_newton(double x_0, double f, double ffd, double fsd, double e, double exact); int main() { double a = 1.0, b = 2.0, error = 0.000001, exact = 1.412391172023884, c = 1.5, d = 2.5; double f_a = pow(a-2,2)-log(a), f_b = pow(b-2,2)-log(b), f_c = pow(c-2,2)- log(c); // bisection method cout << "The bisection method: " << endl; double e_bisec = 0.0001; int bisect_count = bisection(a, b, f_a, e_bisec, exact); cout << "The # of it. needed to reach a result w/ 10^(-5) accuracy = " << bisect_count << endl; cout << endl; // secant method cout << "The secant method: " << endl; int secant_count = secant(a, b, f_a, f_b, error, exact); cout << "The # of it. needed to reach a result w/ 10^(-5) accuracy = " << secant_count << endl; cout << endl; // Newton's method cout << "The Newton's Method: " << endl; int newton_count = newton(c, f_c, error, exact); cout << "The # of it. needed to reach a result w/ 10^(-5) accuracy = "

#### You've reached the end of your free preview.

Want to read all 3 pages?

• Spring '14
• DavidJ.Swinarski

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern