I think it has nothing to do with your programmings skills. For this method to work best yo have to have your initial guess, as close as possible to the real root, or the method may fail to converge.
Readall about it in http://en.wikipedia.org/wiki/Newton%27s_method
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
Some ppl take it a step further and have the program guess an approximate starting point:
[tex]x^3-x = 0[/tex]
By trying values from say x values from -10000 to 10000 and incrementing by 0.01 or something to find where it roughly equals zero.
I haven't thought about complex solutions this is all assuming your code is correct, I haven't bothered to check. I'd try it without complex numbers first...
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
At first have a look at return n in the newton function ;)..
Small coin:
1. Add input check up code. If the user type not-a-number you can't detect failed cin state now...
2. Why not while (abs(x) > error && n <= nmax) ?.. Simple and clear...
3. Use typedef for more comfortable coding with templates, for example:
typedef complex<double> Complex;
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
>I don't think Newton's Method can be used to find complex roots.
Do you have proof that you can't use newton's method for complex roots? I reckon it possible as long as you specify an initial starting point for the complex part of the solution.
"Newton's method also works in the complex numbers; for example, it can be used to find complex roots of polynomials."
http://en.citizendium.org/wiki/Newton's_method
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
hi please im want from you to solve this qustion
Project 1: Find the root of the function
f(x) = (4+x)^2e^-x = 0
By using
1) Secant Method
2) Newton Method
3) By Accelerated Newton Method
Take an initial guess and iterate over using while loop (as suggested in the algorithm) unless you get a very close match.
ithelp
Nearly a Posting Maven
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128