One numerical method for calculating the cubic root of a number VX is by using i
ID: 3704397 • Letter: O
Question
One numerical method for calculating the cubic root of a number VX is by using iterations. The process starts by choosing a value x1 as a first estimate of the solution. Using this value, a second a more accurate value X2 can be calculated with X2-6, + 2%)/3, which is then used for calculating a third, and accurate value x3, and so on. The general equation for calculating the value of xifrom x, is more Xi+1 Write an m-file which uses x 100 as the first estimate to calculate the cube-root of 100 (xthe cube root of the number you're calculating). Stop the looping when the relative error with each iteration is smaller than le-5. I.e. E =-tl- . Determine the number of iterations required to achieve this criterion and print out the value using fprintf. Xi E.g. The number of iterations required is 16 and the cube root of 999 is 9.996666, using x1-999.Explanation / Answer
% Hi! below is the code. Explanation is in the comments.
xi=100; % initialise xi to 100 as mentioned in the question
n=0; % n stores the number of iterations, initially 0
while 1 % infinite loop runs forever
xiplus1=((100/(xi^2))+(2*xi))/3; % calaculate xiplus1 according to equation
if abs(xiplus1-xi)<1e-5
% the above expression checks if the difference between successive
% iterations is less than 10^-5 or 1e-5
break; % if it is true then control of the program exits the infinite loop
end
% if the exit condition is not satisfied
xi=xiplus1; % we update the value of xi for the next iteration
n=n+1; % we increment the number of iterations by 1
end % that's it
formatSpec='The number of iterations required is %d and the cube root of 100 is %.5f, using x1=100.';
fprintf(formatSpec,n,xiplus1); %printing as specified
%xiplus1 this contains the closest value to the exact root
% you can also use xi
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.