# Thread: Cube Root Algorithm in Matlab

1. ## 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

2. 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

3. 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

4. in that cube root algorithm we have to start with f(x)= x^3 - A , where A is any real number

5. 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

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

,

,

,

,

,

,

,

,

,

,

# cube root matlab of newton raphson

Click on a term to search for related topics.