[go: up one dir, main page]

Menu

[r377]: / idl_lib / bisect.pro  Maximize  Restore  History

Download this file

29 lines (21 with data), 574 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;inverts a function through bisection:
function bisect, fname, x1, x2, tol=tol, params=params
if n_elements(tol) ne 1 then tol=0.0001
f1=call_function(fname, x1, params=params)
f2=call_function(fname, x2, params=params)
xmid=(x1+x2)/2
f0=call_function(fname, xmid, params=params)
;while abs(f0) gt tol do begin
while abs(x1-x2) gt tol do begin
if f0 lt 0 then begin
f1=f0
x1=xmid
endif else begin
f2=f0
x2=xmid
endelse
xmid=(x1+x2)/2
f0=call_function(fname, xmid, params=params)
endwhile
return, xmid
end