Need help solving this problem. 8 Implement a MATLAB function bisection.m of the
ID: 2255995 • Letter: N
Question
Need help solving this problem.
8 Implement a MATLAB function bisection.m of the form function [r, h] = bisection(a, b, f, p, t) % a: Beginning of interval [a, b] %b: End of interval [a, b] % f: function handle y = f(x, p) % p: parameters to pass through to f % t: User-provided tolerance for interval width At each step j -1 to n, carefully choose m as in geometric mean bisection (watch out for zeroes!). Replace [a, b] by the smallest interval with endpoints chosen from a, m, b which keeps the root bracketed. Repeat until a f value exactly vanishes, b- aExplanation / Answer
function [r,h]=bisection(a,b,f,t)
temp='Enter the no. of iterations to be made:';
n=input(temp);
st=ones(1,n+1);
en=ones(1,n+1);
st(1)=a;en(1)=b;
for j=1:n
m(j)=(st(j)+en(j))/2;
if (en(j)-st(j)) > t*max(abs(st(j)),abs(en(j)))
if f(st(j))*f(m(j)) < 0
en(j+1)=m(j);
st(j+1)=st(j);
else if f(m(j))*f(en(j)) < 0
st(j+1)=m(j);
en(j+1)=en(j);
end
end
k(1,j)=st(j);
k(2,j)=en(j);
k(3,j)=f(m(j));
r=m;
else
k(1,j)=0;
k(2,j)=0;
k(3,j)=0;
end
h=k;
end
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.