Ex. 1 Algorithm, function, conditional statements, and loops Given a continuous
ID: 3589704 • Letter: E
Question
Ex. 1 Algorithm, function, conditional statements, and loops Given a continuous function f over an interval [a·b] such that sign(f(a)) sign(f(b)) find r e [ such that f(r)-0. The bisection method consists in dividing the interval [a:b] into two sub-intervals lad and [c of equal size. Then either f(a) and f(c) or f(c) and f(b) will have different signs. In case c = r we stop and return c, otherwise the process is repeated over the interval where the sign changes. The process of narrowing down the interval will only end when the error is smaller than a bound specifed by the user. 1. Write a clear algorithm describing the bisection method 2. Implement the previous algorithm using a MATLAB function ote the degree of accuracy should be at least 0,001 (stricty positive and less than 0001) MATLAB functionExplanation / Answer
1)Given a function f (x) continuous on an interval [a,b] and f (a) * f (b) < 0
Do
c = (a+b)/2
if f (a) * f (c) < 0 then b = c
else a = c
error=abs(0-f(c));
while (error>tolerance specified)
2)
function [m,i]=bisect(f,a,b,tol)
%tol isthe tolerance, a and b are the start and end of the range in which
%root is to be found
m=(a+b)/2;%%mid point of interval
i=0;%No.of iterations
k=(b-a);%interval in which root is contained
if f(a)*f(b)>0
disp('No root in initial interval!!!exiting')
else
while (k>tol)%if the interval becomes less tolerance, the loop will break
i=i+1;
if (f(a)*f(m)<0)%if product is negative then the root ies between a and m
b=m;
else %else it lies between m and a
a=m;
end
m=(a+b)/2;%updated midpoint
k=abs((0-f(m)));%updated interval
end
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.