Question:0 The code for a MATLAB function is given below. The most important par
ID: 3700989 • Letter: Q
Question
Question:0 The code for a MATLAB function is given below. The most important part of the code has been put inside a box. There are S logical mistakes in the code inside the box Circle the mistakes and write the corrections in the space glven on the right side rianc cion I root, ea, i terl-newtraph nevtraphi Newton-Raphson root Location zsrDea I fune, dfune, xr, s, maxít, var argini foot, ea,iteri-neweraph ( func, dtuno, xE, es,maxit l.p2. uses Neuton-Raphson method to find the root of tune input: fune- nane of function 9 dfuncname of derivative of tunction xinitial guess y es -desired relative error [def^ult-o.ooo1 % maxit -maximum allowable iterations Lae fault- 50 pl,p2additional parameters used by tunction s output: root real root a approximate relative error (8 8 iter number of iterations if nargin=maxit, break, end end root = xrold;Explanation / Answer
while (1)%no mistake
xrold=xr;%no mistake
xr=xr-func(xr)/func(xr);%mistake 1
correction:
xr=xr-func(xr)/dfunc(xr);
iter=iter+2;%mistake 2
correction:
iter=iter+1;
if xr~=0,ea=abs((xr-xrold)/xold)*100;end%mistake 3
correction:
if xr ~= 0, ea = abs((xr - xrold)/xr) * 100; end
if ea >= es | iter >= maxit, break, end%mistake 4
correction:
if ea <= es | iter >= maxit, break, end
end
root=xrold;%mistake 5
correction:
root = xr;
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.