Advertisement
Guest User

bisection in octave, with error somewhere

a guest
Nov 29th, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function nst = bisekt (a, b, eps, f)
  2.     if((f(a) * f(b)) >= 0)
  3.         disp("Invalid arguments! f(a) or f(b) must be negative.");
  4.         disp(f(a));
  5.         disp(f(b));
  6.     return;
  7.     endif
  8.  
  9.     c = (a+b)/2;
  10.     fc = f(c);
  11.     if (abs(fc) < eps)
  12.         nst = c;
  13.     else
  14.         if (fc > 0)
  15.             nst = bisekt(c, b, eps, f);
  16.         else
  17.             nst = bisekt(a, c, eps, f);
  18.         endif
  19.     endif
  20. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement