Advertisement
Guest User

bisection in octave, with error somewhere

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