An efficient way of computing the cube root of a number N is to compute the root
ID: 3853872 • Letter: A
Question
An efficient way of computing the cube root of a number N is to compute the root of f(x) = x^3 - N = 0 with the method of Newton Raphson, namely: x_n+1 = x_n - [f(x_n)/f'(x_n)] Combining the two equations and rearranging terms gives the recursive (iterative) relationship x_n+1 = 1/3 middot [2x^3_n + N/x^2_n] where x_n+1 is the next guess or iteration. Write a MATLAB program that will prompt the user for a number N and compute the cube root of N via the Newton Raphson technique above and use the simple convergence test |x_n+1 - x_n/x_n| lessthanorequalto epsilon where xi is some very small number, say 0.000001. The program should then print the number N, its cube root, and the number of iterations needed to compute the result. It should also print MATLAB's nthroot value of N.Explanation / Answer
Answer for Question:
This below code is compute the cube root of given equation using newtons rapsons method.
See the below code:
function guess = my_cube_root(a)
% Function computes the cube_root of a number using the newton raphson
% method where the nth root of any number is given by successive
% approximations of % of x_k+1 = (1/n)*[(n-1)*x_k + a/((x_k^(n-1))]
% for the cube root this approximation would be x_k+1 = (1/3)[2*x_k + A/(x^2)]
guess = a/3;
epsilon = 1.0e-6;
delta = guess^3 - a;
while(abs(delta) > epsilon)
guess = (1/3)*(2*guess + (a/guess^2));
delta = guess^3 - a;
fprintf('Cube root guess : %f Actual cube : %f Estimated cube: %f ',guess,a,guess^3);
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.