Problem 5 (10 points, CCOs 2 & 5) To solve the non-linear eq…

Written by Anonymous on June 1, 2026 in Uncategorized with no comments.

Questions

Prоblem 5 (10 pоints, CCOs 2 & 5) Tо solve the non-lineаr equаtion , аn AI wrote 2 different MATLAB functions named bisect implementing the Bisection method as covered in class, and secant implementing the Secant method as covered in class.  As input, each function has the anonymous function f, two values of the independent variable a and b, defining either the initial interval (bisect) or the initial two guesses (secant), the maximum number of iterations to be performed Nmax, and the acceptable tolerance  epsok.  Attempts to use either MATLAB function to solve a non-linear equation have not been successful. Analyze each MATLAB function and either identify and describe all errors that were made in the function and provide the corrected code segment, or state that the function code is correct, and the mistake must have been made in the variables passed into the function. 1  function x = bisect(f,a,b,Nmax,epsok)2  fa = f(a);3 if fa*f(b) > 04     error('Invalid starting interval.n');5 end6 N = min(Nmax,ceil(log((b-a)/(2*epsok))/log(2)));7 x = (b+a)/2; fx = f(x);8 for n = 1:N9     if fa*fx < 010        a = x; fa = fx;11    elseif fa*fx > 012        b = x; 13    else14        break;15    end16    x = (b+a)/2; fx = f(x);17 end18 end 1 function x = secant(f,a,b,Nmax,epsok)2 fa = f(a); 3 x = b; fx = f(x);4 for i = 1:Nmax5   x = x-fx/(fa-fx)*(a-x);6   fx = f(x); 7   if abs(fx)

Comments are closed.