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

Write a Matlab function that will find the zero crossing brackets of the followi

ID: 3757590 • Letter: W

Question

Write a Matlab function that will find the zero crossing brackets of the following functions:

1. f(x) = cos(x), over the interval [0, 2pi] with a bracket size of 0.01;

2. g(x) = x^2 -3x +2, over the interval [0,4] with a bracket size of 0.01;

Hint 1: The f(x) = cos(x) has zeros at pi and 3pi/2. Where g(x) has zeros at x=1 and x=2.

Hint 2: Use similar code to the example provided in class with one extra input called option. Your code should look like this:


function [n,b]=Brackets_HW(Xmin,Xmax, interval, option)
n = 0;
x = Xmin:interval:Xmax;
     if option == 1
        fx = cos(x);
     else
        fx=x.*x-3*x+2;
     end

     ...

end

.

Explanation / Answer

CODE :

1)

given: f(x), xmin, xmax, n

dx = (xmax xmin)/n

xleft = xmin

i = 0

while i < n

i i + 1

xright = xleft + dx

if f(x) changes sign in [xleft, xright]

save [xleft, xright] for further root-finding

end

xleft = xright

end

2)

initialize: a = . . ., b = . . .

for k = 1, 2, . . .

xm = a + (b a)/2

if sign (g(xm)) = sign (g(xa))

a = xm

else

b = xm

end

if converged, stop

end

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