- #1
Jtenbroek
- 2
- 0
Having a lot of trouble the my C++ course, loops especially. This is the assignment giving me trouble
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) = x2e-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.
These files were given;
double
eff(double x)
{
return x*x * exp(-x) - 2;
}
double
effPrime(double x)
{
return 2.0 * x * exp(-x) - x * x * exp(-x);
}
This is all I have so far, not even sure how to begin
#include "assign4.h"
#include <cmath>
double Newton(double x, double tol, int maxIt); {
return x_1 = x_o - (f(x_o) / f(x_o));
}
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) = x2e-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.
These files were given;
double
eff(double x)
{
return x*x * exp(-x) - 2;
}
double
effPrime(double x)
{
return 2.0 * x * exp(-x) - x * x * exp(-x);
}
This is all I have so far, not even sure how to begin
#include "assign4.h"
#include <cmath>
double Newton(double x, double tol, int maxIt); {
return x_1 = x_o - (f(x_o) / f(x_o));
}