Advertisement
Guest User

Bisection in Octave, correct version.

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