Last active
August 29, 2015 14:06
-
-
Save dmadisetti/0e057c97baa5e088fd0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Second stab at matlab | |
function out = biSect(funct,hi,lo,x) | |
if hi < lo, | |
err = MException('MATLAB:ambiguousSyntax','Usage biSect(funct,hi,lo,x). hi cannot be lower rhar low.'); | |
throw(err); | |
end | |
new = lo + (hi - lo)/2; | |
apprx = funct(new); | |
disp(abs((new - x)/2)); | |
disp(apprx); | |
% Let's check to see if it hit the needed level | |
if abs((new - x)/2) < 0.01 || apprx == 0, | |
out = new; | |
return; | |
end | |
if apprx >= 0, | |
hi = new; | |
elseif apprx < 0, | |
lo = new; | |
end | |
out = biSect(funct,hi,lo,new); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment