Results 1 to 3 of 3

Math Help - Newton Raphson Method ,Help needed

  1. #1
    Newbie
    Joined
    Sep 2008
    Posts
    10

    Newton Raphson Method ,Help needed

    Hi, i have been asked to create a function newton.m which takes as input f(x),f'(x) and root esitmate x0 and throws out the true root of f(x) using the newton raphson method.
    after i have created my file,i have to find the root of the 75^(1/3) which is the cuberoot of 75

    here is where i have reached thus far:

    dont know whats going wrong.

    function [root,x] = newton(a,tol)
    f(a)=75^(1/3)
    fp(a)=0
    test = abs(f(a));
    i = 0;
    x(i+1) = a;
    %while test > tol
    for i=1:30
    a = a - f(a)/fp(a);
    test = abs(f(a));
    i = i+1;
    x(i+2) = a;
    end
    i

    root = a;



    can anyone tell me wherei m going wrong,here is what i get when i try to run the file:

    >> newton(1,1e-6)

    f =

    4.2172


    fp =

    0

    ??? Attempted to access f(-Inf); index must be a positive integer or logical.

    Error in ==> newton at 11
    test = abs(f(a));
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by mithilesh View Post
    Hi, i have been asked to create a function newton.m which takes as input f(x),f'(x) and root esitmate x0 and throws out the true root of f(x) using the newton raphson method.
    after i have created my file,i have to find the root of the 75^(1/3) which is the cuberoot of 75

    here is where i have reached thus far:

    dont know whats going wrong.

    function [root,x] = newton(a,tol)
    f(a)=75^(1/3)
    fp(a)=0
    test = abs(f(a));
    i = 0;
    x(i+1) = a;
    %while test > tol
    for i=1:30
    a = a - f(a)/fp(a);
    test = abs(f(a));
    i = i+1;
    x(i+2) = a;
    end
    i

    root = a;



    can anyone tell me wherei m going wrong,here is what i get when i try to run the file:

    >> newton(1,1e-6)

    f =

    4.2172


    fp =

    0

    ??? Attempted to access f(-Inf); index must be a positive integer or logical.

    Error in ==> newton at 11
    test = abs(f(a));
    First you are looking for the cube root of 75, so we want the root of the equation:

    f(x)=x^3-75

    and

    f'(x)=5x^2

    Then the NR ittereation is:

    x_{new}=x_{old}-\frac{f(x_{old})}{f'(x_{old})}

    so we start with functions defining f and f'

    Code:
    function rv=ffcubert(x)
       rv=x^3-75;
    Code:
    function rv=ffdcubert(x)
       rv=3*x^2;
    Then the NR itteration:

    Code:
    function rt=NRroot(f,fdot,x0,tol)
    %================================================
    % f the function we wish to find the root of (function handle)
    % fdot the derivative of f
    % x0 initial guess at the root
    % tol stopping tolerance
    %================================================
       xx=x0;
       err=1e6;
       while err>tol
         fxx=feval(f,xx);
         fxxdot=feval(fdot,xx);
         xnew=xx-fxx/fxxdot;
         err=abs(xnew-xx);
         xx=xnew;
      end
      rt=xx;
    Then the call command:

    Code:
     >> NRroot(@ffcubert,@ffdcubert,1,0.01) 
    
    ans=
    
    4.2172
    
    >>
    RonL
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Sep 2008
    Posts
    10
    Thank you,captain black. and also i had one more request,if u can look at the problem in very urgent section.
    i m having a problem plotting the root,
    any sort of help will be appreciated


    thank you again.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Newton raphson method
    Posted in the Calculus Forum
    Replies: 5
    Last Post: April 4th 2011, 11:44 AM
  2. Newton Raphson method
    Posted in the Calculus Forum
    Replies: 4
    Last Post: May 24th 2010, 06:38 AM
  3. Newton-Raphson method
    Posted in the Calculus Forum
    Replies: 3
    Last Post: December 30th 2009, 07:13 AM
  4. Newton Raphson Method?????? HELP!
    Posted in the Calculus Forum
    Replies: 3
    Last Post: March 5th 2007, 09:37 AM
  5. Help- Newton - Raphson Method
    Posted in the Calculus Forum
    Replies: 3
    Last Post: July 12th 2006, 07:49 AM

Search Tags


/mathhelpforum @mathhelpforum