-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of the proposed solution for the delay differential equat…
…ion issue #1.
- Loading branch information
1 parent
7d83dc7
commit fd52c31
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import numpy as np | ||
from ddeint import ddeint | ||
from pylab import array, sin, linspace, subplots | ||
|
||
tau = 30.0 | ||
|
||
|
||
def foo(t): | ||
if t < 10.0: | ||
return 0.0 | ||
elif 10.0 <= t < 10.0 * np.pi: | ||
return 1.0 | ||
else: | ||
return 10.0 * sin(t * 0.5) | ||
|
||
|
||
def values_before_zero(t): | ||
return array([0.0, 0.0]) | ||
|
||
|
||
def model(Y, t): | ||
x, y = Y(t) | ||
x_tau, y_tau = Y(t - tau) | ||
return array([foo(t), x_tau]) | ||
|
||
|
||
tt = linspace(0, 100, 1000) | ||
yy = ddeint(model, values_before_zero, tt) | ||
|
||
fig, ax = subplots(1, figsize=(8, 4)) | ||
|
||
ax.plot(tt, [x[0] for x in yy], label="trace1") | ||
ax.plot(tt, [x[1] for x in yy], label="trace2") | ||
fig.legend(loc='upper center', borderaxespad=2.0) | ||
fig.show() |