Giter Club home page Giter Club logo

ddeint's People

Contributors

zulko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ddeint's Issues

Cannot Solve First Order Plus Delay Time(FOPDT)

Hi, I try to simulate FOPDT using ddeint. However, it doesn't work for me.
May I have your advice on this?

My system is as shown:

dxdt = (-x(t)+Kp*u(t-d))/taup

where Kp = 1.0 ; d = 180 ; taup = 181 
x(0) = 0.0 and u is a step change from 0 to 0.3

model = lambda x,t,d,Kp,taup : (-x(t)+Kp*u(t-d))/taup
g = lambda t : 0

tt=np.linspace(0,1440,1000)
yy=ddeint(model,g,tt,fargs=(180,1.0,181))

plt.plot(tt,yy)

solving 7 coupled odes with different delays

Hi Zulko,

firstly, thank you for writing ddeint!. I want to solve 7 coupled differential equations with different delays (e.g.,
z1 = (Jd1d1 * Y1(t-d1) + Jd1d2 * Y2(t-d2) + Jd1fsi * Y3(t-d3) + Jd1TA * Y4(t-d4) + Jd1TI * Y5(t-d5) + Jd1ctx * (2. * np.sin(q(t-d6)) + 2.5))
z2 = (Jd2d1 * Y1(t-d21) + Jd2d2 * Y2(t-d22) + Jd2fsi * Y3 + Jd2TA * Y4 + Jd2TI * Y5(t-d25) + Jd2ctx * (2. * np.sin(q(t-d26)) + 2.5))
z3 = (Jfsifsi * Y3(t-d33) + JfsiTA * Y4(t-d34) + JfsiTI * Y5 + Jfsictx * (2. * np.sin(q(t-d36)) + 2.5))
, ...
)
and i'm afraid if ddeint can solve equations like what I want.

Thank you so much,
Atefeh

Incosistency with the solution of odeint when time delay is zero

Hi,

I have a problem about the solution given by ddeint when time delay is set to zero. I expect in this case that the solution is the same as that solved by odeint package. However, there are small deviations from the result of odeint when time delay is zero.

For my dynamc system, I expect the evolution converges to stable states without time delay, which is observed using odeint.

Here is my dynamics: dx/dt = 0.1 + x * (1-x(t-\tau)/5) * (x-1) + 4 * x**2 / (5 + x); \tau is time delay. If it is set zero, then x should converge to some constant. But the solution given by ddeint dose not converge to a stable state.

Thanks for any help!

Michael

Solving second order delay differential equations

Hi Zulko,

firstly, thank you for writing ddeint!. I am trying to solve an initial value problem for the case that x''(t) is known and depends on x(t-dt). In scipy without the delay I do this as following:

def function(z, t):
return np.array([x''(z[1]), z[0]])

then odeint returns an np.array of [x',x]

However in ddeint this seems difficult as I cannot index z. Any help would be appreciated.

Cheers!

Self adjusting integration step?

Not an issue per se, but the only way I can think of contacting you. This package uses scipy's odeint in the background, right? odeint has a self adjusting time step, such that the array of time instants used is only an array to query the integrated function in, not the actual time steps. Does ddeint not do the same? From what I gather from the code, it should, but when integrateing a simple one variable regulatory function I get different results depending on the time array passed to the function, for some parameters. So much so, that in some cases it diverges awfuly due to numerical errors, and in other cases it correctly displays oscilations.

This is the function in question, just in case:

def model(x, t, d, b, x0, h, tau):
    return -d * x(t) + b/(1+(x(t-tau)/x0)**h)

Citing ddeint

If you use Zenodo or some other repository to deposit ddeint and create a DOI, we could cite it when we use it in our work.

Numpy 1.19 deprecation warning

Since numpy 1.19 a deprecation warning is raised at line 145, namely
VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray

The warning can be turned off with np.warnings.filterwarnings('ignore', category=np.VisibleDeprecationWarning), but still, the issue might need adressing. I actualy don't know why the warning is raised, since the lines 144-145

    results = [dde_.integrate(dde_.t + dt) for dt in np.diff(tt)]
    return np.array([g(tt[0])] + results)

shouldn't return a ragged array.

example lotka.py error

--> python lotka.py
Computing for d=0.00
capi_return is NULL
Call-back cb_f_in_dvode__user__routines failed.
Traceback (most recent call last):
File "lo.py", line 19, in
yy = ddeint(model,g,tt,fargs=(d,))
File "/usr/local/lib/python2.7/site-packages/ddeint/ddeint.py", line 140, in ddeint
results = [dde_.integrate(dde_.t + dt) for dt in np.diff(tt)]
File "/usr/local/lib/python2.7/site-packages/ddeint/ddeint.py", line 62, in integrate
scipy.integrate.ode.integrate(self,t,step,relax)
File "/usr/local/lib/python2.7/site-packages/scipy/integrate/_ode.py", line 408, in integrate
self.f_params, self.jac_params)
File "/usr/local/lib/python2.7/site-packages/scipy/integrate/_ode.py", line 865, in run
y1, t, istate = self.runner(*args)
File "/usr/local/lib/python2.7/site-packages/ddeint/ddeint.py", line 56, in f2
return f(self.Y,t,*args)
File "lo.py", line 8, in model
x,y = Y(t)
File "/usr/local/lib/python2.7/site-packages/ddeint/ddeint.py", line 42, in call
return (self.g(t) if (t<=self.tc) else self.itpr(t))
File "/usr/local/lib/python2.7/site-packages/scipy/interpolate/polyint.py", line 79, in call
y = self._evaluate(x)
File "/usr/local/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 608, in _evaluate
y_new = self._call(self, x_new)
File "/usr/local/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 566, in _call_linear
y_lo = self._y[lo]
IndexError: index 2 is out of bounds for axis 0 with size 2

Can't install with pip?

This seems like a great module! I love clean APIs like you seem to have implemented. Unfortunately pip seems to give me errors when trying to install; any ideas?

josh@schism:~/Research/projects$ pip3 install ddeint
Collecting ddeint
  Using cached ddeint-0.1.02.tar.gz
    Complete output from command python setup.py egg_info:
    Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.14.tar.gz
    Extracting in /var/folders/sf/pl_p088d46304npx9csknxq40000gn/T/tmpesz7da9o
    Traceback (most recent call last):
      File "/opt/anaconda3/lib/python3.5/site-packages/ez_setup.py", line 143, in use_setuptools
        raise ImportError
    ImportError

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/sf/pl_p088d46304npx9csknxq40000gn/T/pip-build-pqh28rf2/ddeint/setup.py", line 2, in <module>
        ez_setup.use_setuptools()
      File "/opt/anaconda3/lib/python3.5/site-packages/ez_setup.py", line 145, in use_setuptools
        return _do_download(version, download_base, to_dir, download_delay)
      File "/opt/anaconda3/lib/python3.5/site-packages/ez_setup.py", line 125, in _do_download
        _build_egg(egg, tarball, to_dir)
      File "/opt/anaconda3/lib/python3.5/site-packages/ez_setup.py", line 99, in _build_egg
        _extractall(tar)
      File "/opt/anaconda3/lib/python3.5/site-packages/ez_setup.py", line 467, in _extractall
        self.chown(tarinfo, dirpath)
    TypeError: chown() missing 1 required positional argument: 'numeric_owner'

Code in the README to illustrate usage of ddeint does not work

Hi,
The piece of code in the README to illustrate the basic usage of ddeint does not work for me.
Using

from pylab import cos, linspace, subplots
from ddeint import ddeint

# We solve the following system:
# Y(t) = 1 for t < 0
# dY/dt = -Y(t - 3cos(t)**2) for t > 0

def values_before_zero(t):
    return 1

def model(Y, t):
    return -Y(t - 3 * cos(Y(t)) ** 2)

tt = linspace(0, 30, 2000)
yy = ddeint(model, values_before_zero, tt)

I got the error message

  File "/usr/lib/python3.10/site-packages/ddeint/ddeint.py", line 145, in ddeint
    return np.array([g(tt[0])] + results)
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2000,) + inhomogeneous part.

I use scipy version 1.10.1
Thanks for the help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.