Advertisement
DMG

SONE :: Bisection method

DMG
Nov 7th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.42 KB | None | 0 0
  1. function [x] = bisection_method(a, b, max_error, my_function)
  2.     x_0 = feval(my_function, (a+b)/2);
  3.     x = (a+b)/2;
  4.    
  5.     if abs(b-a) < max_error || x_0 == 0
  6.         return;
  7.     end
  8.    
  9.     if x_0*feval(my_function, a) < 0
  10.         x = bisection_method(a, x, max_error, my_function);
  11.     end
  12.    
  13.     if x_0*feval(my_function, b) < 0
  14.         x = bisection_method(x, b, max_error, my_function);
  15.     end
  16. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement