Bisection - % fL = f(L); fR = f(R); tol = 10^-6*(R-L);...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function xStar = Bisection(f,L,R) % f is a handle to a continuous function f(x) of a single variable. % L and R define an interval [L,R] and f(L)f(R) < 0 % % xStar is an approximate root of f with the property that it % is within |R-L|/10^6 of a true root.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % fL = f(L); fR = f(R); tol = 10^-6*(R-L); while abs(R-L) &gt; tol mid = (L+R)/2; fmid = f(mid); if fL*fmid&lt;=0 % There is a root in [L,mid]. R = mid; fR = fmid; else % There is a root in [mid,R]. L = mid; fL = fmid; end end xStar = (L+R)/2;...
View Full Document

Ask a homework question - tutors are online