source: production/sydney_2006/find_max.py @ 3171

Last change on this file since 3171 was 2878, checked in by sexton, 18 years ago

intro updates

File size: 1.4 KB
Line 
1"""
2Determining maximum of SMF slump surface elevation function.
3Jane Sexton, GA 2006
4"""
5
6from math import exp, cosh
7import Numeric
8
9
10# Grilli and Watts 2005 example
11dx = 2.0
12x0 = 10.0
13y0 = 0.0
14w = 2.0
15kappa = 3
16g = 9.8
17d = 0.259
18T = 0.052
19theta = 15.0 
20lam0 = 5.0 
21   
22def func(x,y,kappad):
23    numerator = exp(-((x-x0)/lam0)**2.0) - kappad*exp(-((x-dx-x0)/lam0)**2.0)
24    denominator = cosh(kappa*(y-y0)/(w+lam0))**2.0
25    return -numerator/denominator
26
27def dfuncdx(x,kappad):
28    dfdx = (x-x0)*exp(-((x-x0)/lam0)**2.0)-kappad*(x-dx-x0)*exp(-((x-dx-x0)/lam0)**2.0)
29    return dfdx
30
31step = 0.001
32x = x0
33deriv = 10
34tol = 0.001
35c = 0
36direction = 'negative'
37while c < 100000 and deriv > 0:
38    deriv = dfuncdx(x,0.83)
39    if deriv < 0: xstar = x
40    if direction == 'positive': x += step
41    if direction == 'negative': x -= step
42    c += 1
43
44print 'location of maximum of surface elevation function: xstar = %f' % (xstar/lam0)
45const = 1.0 #a3D = ? #sydney = 86? and kappad=1
46
47x = arange(-20,25,0.001)
48y = arange(-10,10,0.1)
49X,Y = meshgrid(x,y)
50
51test = 0.0
52for xi in x:
53    testi = func(xi,0.0,0.83)
54    if direction == 'positive':
55        if testi > test:
56            test = testi
57            xstar = xi
58    else:
59        if testi < test:
60            test = testi
61            xstar = xi
62   
63print 'check: xstar = %f and eta(xstar) = %f' %(xstar/lam0, test)
Note: See TracBrowser for help on using the repository browser.