MATLAB: Finding the 5th Root using Newton's Method

In summary, the fifth root of a number is calculated using a userdefined function. The function takes in a number as input and outputs the fifth root of that number.
  • #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.
 
Physics news on Phys.org
  • #2
Your code doesn't even compile. What in the world does while n == 1:i mean? You should instead put the E term in the while statement alongside the 'break' condition. Here is a nice skeleton code I have written

Code:
% Define parameters
endCondition = 0.00001;

E = inf; % Initialize such that while loop begins
while E > endCondition
    % code to compute new estimate
    % Update E (for use in the while loop compare)
end
 
Last edited:
  • #3
i have tried to apply what the both of you said but it is not working for me. Here is what i did. Please let me know what i did wrong.
function [y]= fifthroot (P)
x=p
xi=1
i=5
endcondition=0.00001;
xi=xi-((xi^5-P)/(5*xi)^4);
E=abs((xi-x)/x);
if E<0.00001
break
while E > endcondition %compute new estimate
update E (for use in the while loop compare)
end
end
disp (x)
end
i would really appreciate it
 

FAQ: MATLAB: Finding the 5th Root using Newton's Method

How does Newton's Method work?

Newton's Method is an iterative method used to find the roots of a function. It starts with an initial guess and then uses the slope of the function at that point to find a better approximation of the root. This process is repeated until the desired level of accuracy is achieved.

What is the purpose of finding the 5th root using Newton's Method?

The purpose of finding the 5th root using Newton's Method is to efficiently and accurately calculate the 5th root of a given number. This method is particularly useful when the 5th root of a number cannot be easily calculated by hand or with other methods.

How do you implement Newton's Method in MATLAB?

To implement Newton's Method in MATLAB, you first need to define the function whose root you want to find. Then, you need to choose an initial guess for the root and set a desired level of accuracy. Finally, you can use a loop to iterate through the method until the desired accuracy is achieved.

Are there any limitations or drawbacks to using Newton's Method?

One limitation of Newton's Method is that it may not always converge to the desired root. This can happen if the initial guess is too far from the actual root or if the function has multiple roots. Another drawback is that the method may require a large number of iterations to achieve the desired accuracy, which can make it computationally expensive.

Can Newton's Method be used for functions other than finding roots?

Yes, Newton's Method can also be used to find the minimum or maximum value of a function. This is done by finding the root of the derivative of the function, which represents the slope of the original function. By finding the root of the derivative, we can find the point where the slope is equal to zero, which is the minimum or maximum value of the function.

Similar threads

Back
Top