source: anuga_work/development/sudi/sw_1d/periodic_waves/johns/rootsearch.py @ 7837

Last change on this file since 7837 was 7837, checked in by mungkasi, 12 years ago

Again, adding some codes for 1d problems on debris avalanche and periodic waves.

File size: 465 bytes
Line 
1## module rootsearch
2''' x1,x2 = rootsearch(f,a,b,dx).
3    Searches the interval (a,b) in increments dx for
4    the bounds (x1,x2) of the smallest root of f(x).
5    Returns x1 = x2 = None if no roots were detected.
6'''   
7def rootsearch(f,a,b,dx):
8    x1 = a; f1 = f(a)
9    x2 = a + dx; f2 = f(x2)
10    while f1*f2 > 0.0:
11        if x1  >=  b: return None,None
12        x1 = x2; f1 = f2
13        x2 = x1 + dx; f2 = f(x2)
14    else:
15        return x1,x2
Note: See TracBrowser for help on using the repository browser.