Rewrite the function BiSection to be BiSectionSearch in MATL

Rewrite the function BiSection to be BiSectionSearch in MATLAB. The function will use the bisectionalgorithm to search for a set of roots.  It should do this systematically by applying theBiSection algorithm to a set of overlapping intervals that work through the region of the roots. The function call should be as shown below.

function roots = BiSectionSearch( xStart, xStop, xStep, xOverlap, Function )

%

% Function that uses bisection to search for the roots of f(x)

% Inputs: xStart and xStep - the end points of the search.

%         xStep – the size of interval used in search.

%         xOverlap – the overlap between intervals.

%         Function – the function to be searched.% Outputs: roots - array of roots found in the search.

Test function to solve for the two roots of (x^10)-10*(x^5)+(e^-x)-1 using the BiSectionSearch function. The roots are between -5 and 5.

Solution

function roots = BiSectionSearch( xStart, xStop, xStep, xOverlap, Function )
i = 1;
l = xStart;
u = l+xStep;
tolerance = .00001;
while u <= xStop
% Evaluate both ends of the interval
y1 = feval(Function, l);
y2 = feval(Function, u);
lt = l;
ut = u;
% No sign change
if y1 * y2 > 0
l = u-xOverlap;
u = l+xStep;
continue;
end
% Work with the limits until a root you find
while (abs(ut - lt) >= tolerance)
% Find a new value to be tested as a root
m = (ut + lt)/2;
y3 = feval(Function, m);
if y3 == 0
l = u-xOverlap;
u = l+xStep;
roots(i) = m;
i++;
break;
end
% Update the limits
if y1 * y3 > 0
lt = m;
y1 = y3;
else
ut = m;
end
end

l = u-xOverlap;
u = l+xStep;
end

Rewrite the function BiSection to be BiSectionSearch in MATLAB. The function will use the bisectionalgorithm to search for a set of roots. It should do this sys
Rewrite the function BiSection to be BiSectionSearch in MATLAB. The function will use the bisectionalgorithm to search for a set of roots. It should do this sys

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site