-
Notifications
You must be signed in to change notification settings - Fork 6
/
optic_two.py
68 lines (51 loc) · 1.39 KB
/
optic_two.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import numpy as np
import pylab as pl
from math import sin, cos
from pydelay import dde23
# define the equations
#eqns = { 'x' : '1/tau * x(t-tau) / (1.0 + pow(x(t-tau),10.0)) -0.1*x' }
eqns = { 'x' : '(1/tau) *(beta*pow(cos(x(t-T)-x(t-T-dT)+Phi0),2) -x)' }
#define the parameters
params = {
'tau' : 0.0122,
'beta' : 1.2,
'T' : 24.35,
'dT' : 0.400,
'Phi0' : 0.23*np.pi
}
# Initialise the solver
dde = dde23(eqns=eqns, params=params)
#set the simulation parameters
# (solve from t=0 to t=1000 and limit the maximum step size to 1.0)
tfinal=10000
dde.set_sim_params(tfinal=tfinal, dtmax=0.5, AbsTol=10**-6, RelTol=10**-3)
# set the history of to the constant function 0.5 (using a python lambda function)
histfunc = {
'x': lambda t: 0.3453
}
dde.hist_from_funcs(histfunc, 100)
# run the simulator
dde.run()
# Make a plot of x(t) vs x(t-tau):
# Sample the solution twice with a stepsize of dt=0.1:
# once in the interval
T=params['T']
dT=params['dT']
sol1 = dde.sample((tfinal-80)+T+dT, tfinal, 0.01)
x1 = sol1['x']
t = sol1['t']
# and once between
sol2 = dde.sample((tfinal-80)+dT, tfinal-T, 0.01)
x2 = sol2['x']
# and once between
sol3 = dde.sample((tfinal-80), tfinal-T-dT, 0.01)
x3 = sol3['x']
pl.subplot(211)
pl.plot(t,x1)
pl.xlabel('$x(t)$')
pl.ylabel('$t$')
pl.subplot(212)
pl.plot(x2-x3, x1)
pl.xlabel('$x(t-T)-x(t-T-\delta T)$')
pl.ylabel('$x(t)$')
pl.show()