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

MatLab programming Part 1: Bracketing function Bracketing is used to make initia

ID: 2990547 • Letter: M

Question

MatLab programming

Part 1: Bracketing function Bracketing is used to make initial guesses at the roots ( not to accurately estimate the values of the roots). A root of a function (x) is bracketed on the interval [a, b] if f(o) and f(b) have opposite sign. A sign change occurs for singularities as well as roots. Write Matlab function foo3 which evaluates f(x) = x ?x^1/3 ?2 for any scalar or vector of x values. Write Matlab function mybracket which implements the following bracketing algorithm. given: f(x), xmin, xmox, n dx s (xmox - xmin)/n a= xmin i = 0 while i

Explanation / Answer

%------------------------------------

%function foo3

%-----------------------------------------

function [y]=foo3(x)
y=x-x.^(1/3)-2;
end

%------------------------------------------

%script part 1

%------------------------------

x=linspace(3,10,100);

y=foo3(x);

plot(x,y)

grid on

%----------------------------------

% script for mybracket function

%-----------------------------------

function []=mybracket(f,xmin,xmax,n)



dx=(xmax-xmin)/n;
a=xmin;
for i=1:n
b=a+dx;
c=f(a);
d=f(b);
if c*d<0
str=['one bracket is [',num2str(a),',',num2str(b),'].'];
disp(str);
end
a=b;
end

end