Need help with newton's theorem (matlab)

After running script i put inittial starting point -3, tolerance parameter = 1e-5 , max iteration = 35,
however there is something wrong with the newton script i need to know what it is please thank you. i think the output after plotting fplot(function, [-15,1]) there is something wrong but i am not sure .
any help will be appreicated thanks

 채택된 답변

Richard Brown
Richard Brown 2012년 4월 16일

1 개 추천

It works fine - you're just using a (contrived!) nasty example. Plot your function between -3 and 20 and see where the first Newton step takes you

댓글 수: 6

PG
PG 2012년 4월 16일
apparently there might be a trivial problem with the newton script and i need to know how to fix it, but I can't see anything wrong, can you?
Richard Brown
Richard Brown 2012년 4월 16일
no, your script is just fine. You're starting at a point with near zero slope, and that's when Newton's method goes south. Try starting at -1.5, you'll find it converges in a couple of steps.
Richard Brown
Richard Brown 2012년 4월 16일
Although you may want to think about reordering your loop a bit - on the iteration that it converges, you're not displaying the final f(x) that caused it to converge (i.e. you don't want that i = i-1 line, but to resolve that problem you need to rearrange slightly)
PG
PG 2012년 4월 16일
i mean the problem is that it shouldn't converge but we still get an answer, why?
Richard Brown
Richard Brown 2012년 4월 16일
It doesn't converge - your function has a limit of zero as x -> -inf, it ends up taking a step sufficiently far to the left that it reaches your tolerance - but it's not actually found a zero.
PG
PG 2012년 4월 16일
yes so how would i fix the code so that it detects the problem, because right now it actually is telling me it converges,
thanks for your help

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sargondjani
Sargondjani 2012년 4월 16일

0 개 추천

i dont think there is a perfect solution for this... a numerical algorithm that tries to find a minimum will have to stop somewhere: when the solution is 'good enough', ie. when the derivative is very close to zero.
For instance if you look for the maximum of the log function (or min. of -log), the derivate will go to zero as x grows larger, so at some point an optimizer will say: 'now i am sufficiently close. i stop', while in fact it is not maximum, as log is unbounded above...
so you will have to use your own good sense to prevent mistaking a solution for a global minimum (as it can be either a local minimum or not a minimum at all). i pretty sure there doesnt exists an operable algorithmm that always finds the global maximum or minimum as it is just too complicated...
so you will ALWAYS have to rely on analyzing the function in some other way as well...

댓글 수: 1

Richard Brown
Richard Brown 2012년 4월 19일
Just to clarify: the OP is talking about Newton's method (Newton-Raphson) for zero finding, not for optimisation. So it's not trying to find minima at all.

댓글을 달려면 로그인하십시오.

PG
PG 2012년 4월 19일

0 개 추천

what do i put in the stopping condition in the while loop so that the code can detect the derivative is approaching zero?

댓글 수: 3

PG
PG 2012년 4월 19일
the output says that there is a root at around -20 or so, when there is only 1 root at -1.5. to fix this, i ned to add a criterioon for x which emans that i need to make sure whether or not x is converging.. but i don't know how to do that (code-wise)
Richard Brown
Richard Brown 2012년 4월 19일
You need to decide on a condition. It could be that the gradient is sufficiently nonzero, or that the difference between successive x values is also going to zero at a similar rate related to the rate the function value goes to zero, etc. etc. There is no "standard" answer - what you come up with will be a heuristic that works for your problem
PG
PG 2012년 4월 19일
i'm not that comfortable with matlab so i don't really know how to code it, if this was c++ though i would just simply change the precision so that the function can tell the difference between say 0.0000 and 0.0001 or something of that sort, or output a x root if and only if y=0.. but how do i code this in matlab?
thanks for ur help

댓글을 달려면 로그인하십시오.

카테고리

질문:

PG
2012년 4월 16일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by