1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Newton-Raphson method

  1. Nov 22, 2011 #1

    sharks

    User Avatar
    Gold Member

    1. The problem statement, all variables and given/known data
    Solve for positive root of equation: 10 + 3x^2 = e^x


    2. Relevant equations
    The usual Newton-Raphson formula.


    3. The attempt at a solution
    f(x) = 10 + 3x^2 - e^x

    f'(x) = 6x -e^x

    But then my biggest problem, how to find the initial guess? I have looked around, and i can't find a definitive answer on how to find the initial value. From what i understand, i can plot a graph and then look for an estimate. Is that the best method there is?
    Anyway, i plotted a graph and i have no idea how to interpret it, as the two curves don't touch on my graph paper, so i can't figure out an estimate. I get a curve with minimum 3x^2 + 10 and the graph of e^x. Is that correct?
     
  2. jcsd
  3. Nov 22, 2011 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    Are you sure the two curves don't intersect? (Hint: your graph paper only shows a small snap-shot of the real plane.)

    If you don't like to graph, you can always systematically investigate (guess) x values.
    At some point, the LHS will switch from being greater than the RHS to being less.
     
  4. Nov 22, 2011 #3

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    You should also use you knowledge and experience of the way different shaped graphs work to guide you. To plot a graph, you need to make sure that the domain includes the root you want.

    How many roots would you expect?
    Where would you expect to find a positive root?

    Perhaps you didn't go high enough?
     
  5. Nov 22, 2011 #4

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    Do you understand that just choosing an arbitrary starting value, say, x= 1.0, would give you the corrrect answer in less time than it took you to post this?
     
  6. Nov 22, 2011 #5

    sharks

    User Avatar
    Gold Member

    I am aware that most of the time (from what i read in my little online research) any arbitrary value can be chosen, but here i need to choose an initial value that's reasonable so that i can complete the problem in less time (exams, tests) and i also need to make sure that the oscillations don't go on endlessly or give me no roots, as sometimes is the case (again, from what i read and understood).

    However, i asked one of my friends (who also has no definitive idea on how to do this) and he tells me that as a general rule, i should always evaluate f(0) and then use that value as the initial value. Is that correct and common practice? Or am i just being misled into more confusion, if that's even possible?
     
  7. Nov 22, 2011 #6

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    The first thing to do is to do a simple analysis of the function at hand, which is f(x)=10+3x2-ex. The function is continuous everywhere, so that's good. It goes to -∞ (exponentially) as x→+∞, and to +∞ (quadratically) as x→-∞. So there must be at least one zero. Since f(0)=9, at least one of the zeros lies between 0 and +∞.

    Newton-Raphson has big problems when f'(x) is zero. In this case, f'(x)=6x-ex is negative at x=0, negative for very large x, but is positive for x=1. So we have a potential problem. f'(x) is positive for x=2 as well, negative for x=3. Choosing an initial guess between 0 and 2 might well be a very bad idea here.

    The graphs of 10+3x2 and ex do cross somewhere between x=0 and x→+∞. I'll hold off on the rest of my comments on the specific problem at hand you yourself have a better guess as to how to proceed. I will comment on your last post.


    Most of the time you should expect that NR will behave badly. That's why more powerful techniques such as Levenberg–Marquardt only use NR (actually, Gauss-Newton) when the candidate solution is in an a region where Newton's method is well-behaved.

    There are tests to see if something bad has happened. But generic rules to guarantee a good choice? No. For example, ...

    Here's a simple counterexample: f(x)=x^2+2x-1. f(0)=-1, and f'(-1)=0. Kaboom!
     
  8. Nov 22, 2011 #7

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    That's my position too - I plotted the function and found it in less than 10 seconds. Mind you - helps if you have a math-scripting program. It should be clear just looking at the two functions that there is an intersection.

    It comes back to my earlier question: how many roots do you expect the function to have? How well behaved is the function?

    This is not something you can do consistently well on automatic. I'm afraid you just have to work it out. Sketching the graphs was a good start - it's amazing how few people do this.
     
  9. Nov 22, 2011 #8

    sharks

    User Avatar
    Gold Member

    So, to summarize, the best way to go about using the N-R method, is to always start with a graph and then try to approximate the initial value from the graph itself. We don't normally have graph paper in exams, as no such thing is required for N-R (according to my class notes, there is zero mention of drawing up any graphs), but i guess i should try to sketch it as accurately as possible.
     
  10. Nov 22, 2011 #9

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    You can always sketch the graph. You don't need to actually plot anything. It need not be all that accurate so long as you get the important bits. You only need a general idea of where the roots can be found ... maybe avoid cyclic bits, but that is not often a problem in things like exams.

    The rest depends on your access to computers.

    If you are not allowed computers (phones, graphical or programmable calculators etc) in your exams then the N/R problems will be quite simple. If you are allowed computers, then the plots become trivial. Learn to use GNU/Octave for eg. Though a spreadsheet can be used in a pinch.

    In the attachment, the blue line is the function - the red is the exponential and the green is the quadratic.
    With the difference between a quadratic and an exponential, in general, there may be as many as three roots, and as few as none. Do you see how?
     

    Attached Files:

    Last edited: Nov 22, 2011
  11. Nov 23, 2011 #10

    sharks

    User Avatar
    Gold Member

    The Octave software looks very impressive. It greatly simplifies the whole problem, as it gives a clear overview of the problem and i can almost see the root (it's between 4.0 and 4.5). I am downloading the Windows version and will make it a habit of referring to it for all Newton-Raphson problems.

    Thank you all for your much appreciated and precious advice.
     
  12. Nov 23, 2011 #11

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    I've never got the Windows version working ... but I know lots of people have, it's probably some sort of personal failing. The GNU/Linux version gets set up automatically and linux works around the terminal anyway.

    The trick is thinking in terms of everything being a matrix.
    But here are tutorials online.

    That plot was generated with:

    Code (Text):

    x=-5:0.125:5;
    y=10+3.*x.^2;
    z=exp(x);
    plot(x,y-z,x,y,x,z)
    grid
    This samples the functions at 81 evenly spaced discrete points in the domain [-5,5], and generates a plot linking the dots by lines.

    You can zoom in on the root by choosing tighter bounds for x, eg.

    x=3.5:0.125/8:4.5;
    y=10+3.*x.^2-exp(x);
    plot(x,y)

    You can also get it to do the N-R calculations for you by putting each step in a loop.
    eg. finding the square-root of 25, starting at x=4:
    Code (Text):

    octave:1> 0.5*(4+25/4)
    ans =  5.1250
    octave:2> 0.5*(ans+25/ans)
    ans =  5.0015
    octave:3> 0.5*(ans+25/ans)
    ans =  5.0000
    I can repeat a command in the terminal by pressing the up-arrow key.
    For your function, it takes 5 iterations starting from ans=5 to get the root to 4dp.

    Note - there are two turning points? Pick a starting point too close to one of them and it takes quite a long time to converge.
     
    Last edited: Nov 23, 2011
  13. Nov 25, 2011 #12

    sharks

    User Avatar
    Gold Member

    Thanks for the info on how to use the program, Simon Bridge. It's not so simple though, especially for the beginner. Maybe there are other alternatives where you can just click, drag, drop. I don't mind even paid software if it'll let me be lazy. :) I will do a little research on this.

    Cheers!
     
  14. Nov 28, 2011 #13

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    The hardest part is thinking about everything as a vector.
    The visual studio set has drag-and-drop but anything much simpler than these script languages is also highly limited.

    For just plotting a function, it is almost intuitive - just how you'd automatically think of writing it down here - watch:

    lets say you want to plot y=x^2 -1 on the interval [-2,2]...

    Your only decision is to work out how many points you want to use for the plot. Pick a number out of a hat ... the more points you use the smoother the plot, and the slower the calculation. You'll get used to it.

    Let's say 100 points - including the end-points that's 99 steps (that's the hardest part) then:

    a=-2;
    b=2;
    N=100;
    s=(b-a)/(N-1);

    x=a:s:b;
    y=x.^2 -1;
    plot(x,y)


    The difference between y=x^2-1, which you'd naturally write, and y=x.^2-1 is trivial (and due to the fact that x is treated as a vector).

    Seriously - if you want to pursue math and science at all past High School level - you need to learn some math script language anyway. The sooner you get used to it the better you'll do. Otherwise you'll struggle.

    [Mind you - I've not used the windows version ... I gather Matlab and Mathematica are easier to use on Windows. In GNU/Linux, octave is pretty much built in.]
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Newton-Raphson method
  1. Newton-Raphson method (Replies: 6)

  2. Newton Raphson problem (Replies: 1)

Loading...