Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Newtons method

Name: Anonymous 2012-02-08 14:56

So guys I have myself another c++ assignment that is over my head as usual, can i get some pointers or help on how to start this one? All the data is below

One of the most powerful methods used to find the roots of an equation of the form, f(x) = 0, is Newton's method. The procedure is to repeatedly compute a new estimate of the root, y, using a previous estimate of the root, x, and the following computation: y = x - f(x)/f'(x), where f'(x) is the derivative of f(x). If this is repeated often enough (each time replacing x with the new estimate, y), and the initial estimate of the root is close enough to the actual root, then the values of x and y will converge to each other and the root. Two methods are used to stop the iteration process: when the absolute value of the difference between x and y is less than some specified tolerance, when the number of iterations reaches a specified maximum number, maxIterations.

In this assignment you will create a C++ program that implements the function described below. We have provided the following files:

    assign4.h
        This file contains the declarations for the function you are to implement (newton) as well as the functions to be used (eff and effPrime), which are defined in effExp.cpp.
    effExp.cpp
        This file contains the definitions of the functions to be used (eff and effPrime) by your newton function.

The function you are to implement finds a root of the given function eff(x) using Newton's method. The given version of eff(x) implements f(x) = x^2e^-x -2 (where e is the base of the natual logarithm) and effPrime(x) implements its derrivative, but your code could be used to find a root of other functions by substituting different implementations of eff and effPrime. Your program should use both of the above techniques to stop iteration (i.e., it should stop when either condition is satisfied).

The function you are to implement is as follows:

    double newton(double x, double tol, int maxIt)
    Finds a root of eff using Newton's method starting at x and stoping when successive approximations are within tol of each other or maxIt iterations have occured.

Sample Data

x = -1.5, tol = 0.0001, maxIt = 10 should result in -0.901201.

thanks guys for any help!

Name: Anonymous 2012-02-10 10:38

You have a do loop without the while clause at the end.

do
{
    // Stuff
}
while (!opIsAFag);

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List