- #1
pags920
- 21
- 0
Homework Statement
The solution of the nonlinear equation x^5-P=0 gives the fifth root of the number
P. A numerical solution of the equation can be calculated with Newton’s
method. The solution process starts by choosing a value x1 as a first estimate of
the solution. Using this value, a second, more accurate solution x2 can be calculated
with x2=x1-((x1^5-P)/(5*x1^4)) , which is then used for calculating a third, still more
accurate solution x3, and so on. The general equation for calculating the value of
the solution xi+1 from the solution x1 is xi+1 = xi -((xi^5-P)/(5*xi^4)) . Write a userdefined
function that calculates the fifth root of a number. For function name and
arguments use y=fifthroot(P), where the input argument P is the number
whose fifth root is to be determined, and the output argument y is the value (5th sqrt(P)) .
In the program use x=P for the first estimate of the solution. Then, by using the
general equation in a loop, calculate new, more accurate solutions. Stop the looping
when the estimated relative error E defined by is smaller than
0.00001.
Homework Equations
The Attempt at a Solution
Code:
function [y] = fifthroot(P)
format short
x=P;
xi=1;
i=5;
while n==1:i
xi=xi-((xi^5-P)/(5*xi)^4);
E=abs((xi-x)/x);
if E<0.00001
break
end
disp(x)
end
This was my previous attempt. I am not sure whether a for loop or a while loop is the best to use for this situation. My problem is trying to use a previous answer in computing the next answer. Not quite sure how to retain a previous answer for using in the next one.