Results 1 to 5 of 5

Math Help - Cube Root Algorithm in Matlab

  1. #1
    Newbie
    Joined
    Sep 2009
    Posts
    3

    Cube Root Algorithm in Matlab

    Code:
    function[p0,err,k,y]=newton(f,df,p0,delta,epsilon,max1)
    
    %Input - f is the object function input as a string 'f'
    %          df is the derivative of f input as a string 'df'
    %          p0 is the initial approximation to a zero of f
    %          delta is the tolerance for p0
    %          epsilon is the tolerance for the function values y
    %          max is the maximum number of iterations
    % output -p0 is the newton raphson approximation to the zero
    %            err is the error estimate for p0
    %            k is the number of iteration
    %            y is the function value f(p0)
    
    for k=1:max1
      p1=p0-feval(f,p0)/feval(df,p0);
      err=abs(p1-p0);
      relerr=2*err/(abs(p1)+delta);
      p0=p1;
      y=feval(f,p0);
      if (err<delta)|(relerr<delta)|(abs(y)<epsilon),break,end
    end
    This program is the newton raphson iteration to approximate a root
    of f(x)=0 given initial approximation p0 and using the iteration,

    pk= pk-1 - ( f(pk-1)/ f'(pk-1) ) for k = 1,2,3 ....


    Note... k and k-1 are in subscripts of p
    Last edited by CaptainBlack; September 27th 2009 at 08:06 PM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Newbie
    Joined
    Sep 2009
    Posts
    3
    continued from above

    I have to modify the above program to use the cube root algorithm to approximate the cube roots to 10 decimal places of the following

    start with p0=2 and approximate 7^(1/3)


    Here is the cube root algorithm

    pk = ( 2p(k-1) + A / p^2(k-1) ) / 3 for k = 1,2,3 ...

    Note... k and k-1 are in subscripts of p and p square

    I have to modify the given program with this cube root algorithm




    Could someone please help me out on this one.....Thanks
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by hijohn2 View Post
    continued from above

    I have to modify the above program to use the cube root algorithm to approximate the cube roots to 10 decimal places of the following

    start with p0=2 and approximate 7^(1/3)


    Here is the cube root algorithm

    pk = ( 2p(k-1) + A / p^2(k-1) ) / 3 for k = 1,2,3 ...

    Note... k and k-1 are in subscripts of p and p square

    I have to modify the given program with this cube root algorithm




    Could someone please help me out on this one.....Thanks
    What is "A"?

    CB
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    Sep 2009
    Posts
    3
    in that cube root algorithm we have to start with f(x)= x^3 - A , where A is any real number
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by hijohn2 View Post
    continued from above

    I have to modify the above program to use the cube root algorithm to approximate the cube roots to 10 decimal places of the following

    start with p0=2 and approximate 7^(1/3)


    Here is the cube root algorithm

    pk = ( 2p(k-1) + A / p^2(k-1) ) / 3 for k = 1,2,3 ...

    Note... k and k-1 are in subscripts of p and p square

    I have to modify the given program with this cube root algorithm




    Could someone please help me out on this one.....Thanks
    You should at least try to do such things yourself next time, this is already a hand-holding exercise, you should not need more hand holding without some evidence of effort and description of what problems you are finding.

    Code:
    function[p0,err,k,y]=crt(A,p0,delta,epsilon,max1)
    
    %Input - ....
    %          p0 is the initial approximation to a zero of f
    %          delta is the tolerance for p0
    %          epsilon is the tolerance for the function values y
    %          max is the maximum number of iterations
    % output -p0 is the ...
    %            err is the error estimate for p0
    %            k is the number of iteration
    %            y is the function value f(p0)
    
    for k=1:max1
      p1=2*p0+A/(3*p0^2);
      err=abs(p1-p0);
      relerr=2*err/(abs(p1)+delta);
      p0=p1;
      y=feval(f,p0);
      if (err<delta)|(relerr<delta)|(abs(y)<epsilon),break,end
    end
    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Cube root of 5
    Posted in the Algebra Forum
    Replies: 12
    Last Post: May 6th 2011, 07:32 AM
  2. square root + cube root of a number
    Posted in the Algebra Forum
    Replies: 2
    Last Post: December 5th 2010, 10:35 AM
  3. Cube Root times Cube Root
    Posted in the Pre-Calculus Forum
    Replies: 6
    Last Post: December 1st 2009, 06:03 AM
  4. Replies: 2
    Last Post: April 6th 2009, 03:51 AM
  5. Cube root
    Posted in the Algebra Forum
    Replies: 1
    Last Post: March 3rd 2009, 09:53 AM

Search Tags


/mathhelpforum @mathhelpforum