function x=inthalv(a,b,n) x=(a+b)/2; for i=1:n-1 fx=f(x); fa=f(a); fb=f(b); if fx*fa<0 b=x; else a=x; endif x=(a+b)/2; endfor endfunction