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!

Finding roots using Newton's method in MATLAB

  1. Oct 14, 2015 #1
    1. The problem statement, all variables and given/known data
    I am supposed to find the roots of the equation: 10esinx = x2 - 5x +4 in MATLAB using Newton's method with a tolerance of 10-8. There should be three roots.

    2. Relevant equations

    p=po - f(po)/f'(po)

    |p - po| < TOL

    3. The attempt at a solution

    Here is what I have for the code so far:

    Code (Matlab M):

    N=100;
    x=zeros(N+1,1);
    f=x.^2-(5*x)+4-(10*exp(sin(x)));
    fprime= diff(sym(f));
    TOL=1E-7;
    p0=1;
    I=1;
    x(1)=p0;
    while (I<=N+1)
        fp=f(x(I-1));
        fprimep=fprime(x(I-1));
        x(I)=x(I-1)-fp/fprimep;
        if (abs(x(I)-x(I-1))<=TOL)
            Ifinal=I;
            break;
        end
        I=I+1;
        x(I-1)=x(I);
    end
     
    I just keep getting so many errors. MATLAB won't even accept the function itself(but it doesn't specify what the problem is). Any help would be appreciated, as this is the first time I've ever used this program and have no idea what I'm doing. :frown:
     
    Last edited by a moderator: Oct 14, 2015
  2. jcsd
  3. Oct 14, 2015 #2

    jedishrfu

    Staff: Mentor

    What are the error you're getting? Often they will hint what is wrong.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Finding roots using Newton's method in MATLAB
  1. Matlab Newton's Method (Replies: 1)

Loading...