Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question-04 The code for a MATLAB function is given below. The most important pa

ID: 3700987 • Letter: Q

Question

Question-04 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 given on the right side. function [root, ea,iter]-newtraph (func,dfunc, x, es,maxit,varargin) % newtraph: Newton-Raphson root 1 cation zeroes % [root,ea, iter,-newt raph (func, dfunc , xr,es.maxit.pl,p2, ): uses Newton-Raphson method to find the root of fune 8 input: 8 8 func-name of function % dfunc name of derivative of function % xr = initial guess % es -desired relative error (default-0.0001%) % maxit maximum allowable iterations (default - 50) 8 pl,p2,additional parameters used by function 8 output: root = real root % ea approxima te relative error (%) % iter = number of iterations if nargin

Explanation / Answer

Errors are listed below.


Wrong Code Corrected Code Explanation 1. xr = xr - func(xr) / func(xr) xr = xr - func(xr) / defunc(xr) new root is calculated by root - f(x) / f'(x) 2. iter = iter + 2; iter = iter + 1; iter should be incremented by 1 at each iteration of the loop 3. if xr ~= 0 if xr >= 0 realtive error must be calculated as long as root is greater than or equals to 0 4. if ea >= es if ea <= es Loop must break when estimated error is less than or equal to desired relative error 5. root = xrold; root = xr; finally root must be equal to new calculated root xr, not old root
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote