# Cube Root Algorithm in Matlab

• Sep 27th 2009, 02:37 PM
hijohn2
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
• Sep 27th 2009, 02:38 PM
hijohn2
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

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

• Sep 27th 2009, 08:09 PM
CaptainBlack
Quote:

Originally Posted by hijohn2
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

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

What is "A"?

CB
• Sep 27th 2009, 08:19 PM
hijohn2
in that cube root algorithm we have to start with f(x)= x^3 - A , where A is any real number
• Sep 27th 2009, 08:34 PM
CaptainBlack
Quote:

Originally Posted by hijohn2
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

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

```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```