The cubic roots of a is calculated using the iterative Newton\'s method new 3 ol
ID: 1770682 • Letter: T
Question
The cubic roots of a is calculated using the iterative Newton's method new 3 old Where, &" is the initial value. Using this pattern create an user defiled function that evaluates the following: User must choose 1 or 2. If 1, solution is based on the for loop. If 2, solution is based on while loop. The function name should be ferror, cnez cubi wot choice acoidzoahn) a) Create a for loop that evaluates the value of Va for given number of iterations (n) b) Create a while loop that evaluates the value of Va until an error of IE 81s met krror =her-deal hould be ferror, wbic oal xoldExplanation / Answer
Matlab Script:
function [error,xnew] = cubic_root(choice,a,xold,goal,n)
if choice==1
for i=1:n
xnew=(1/3)*((a/(xold^2))+(2*xold));
error = abs((xnew-xold)/xold);
xold = xnew;
end
else
while 1==1
xnew=(1/3)*((a/(xold^2))+(2*xold));
error = abs((xnew-xold)/xold);
if error<1e-8
break;
else
xold = xnew;
end
end
end
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.