odeint

How to incorporate time-varying parameters from lookup table into boost::odeint, c++

≡放荡痞女 提交于 2020-01-05 05:20:13
问题 I am trying to numerically integrate a nonlinear system using boost::odeint. The system has time-varying parameters that are generated externally, and I want to incorporate this into my program. Is this possible with odeint? In Matlab, if you were to do something similar, you would need to interpolate the values as they become available. Thank you in advance for your help! 回答1: Edit: You can solve nonlinear time-varying system easily with odeint . The following example of a nonlinear time

Object Too Deep for Desired Array - scipy.integrate.odeint

心不动则不痛 提交于 2020-01-04 06:46:20
问题 I've just started with Python yesterday, and I'm getting an error using scipy.integrate.odeint . I've defined a function def SIR(x, t, beta, gamma, mu, M): which takes the numpy.array objects x , t , and M ; and the scalar floats beta , gamma , and mu . M is (60,60) in size, but I don't think this matters. x and t are both nonsingleton, with x.shape being (180,) and t.shape being (5000,) . I've tried giving them a singleton dimension, such that they have shapes (180,1) and (5000,1)

Object Too Deep for Desired Array - scipy.integrate.odeint

帅比萌擦擦* 提交于 2020-01-04 06:46:08
问题 I've just started with Python yesterday, and I'm getting an error using scipy.integrate.odeint . I've defined a function def SIR(x, t, beta, gamma, mu, M): which takes the numpy.array objects x , t , and M ; and the scalar floats beta , gamma , and mu . M is (60,60) in size, but I don't think this matters. x and t are both nonsingleton, with x.shape being (180,) and t.shape being (5000,) . I've tried giving them a singleton dimension, such that they have shapes (180,1) and (5000,1)

Using Eigen::VectorXd (Eigen 3.3.4) as a state type in boost::numeric::odeint (Boost 1.65.1)

谁说我不能喝 提交于 2020-01-01 16:37:22
问题 During my work, it would be a requirement for me to use Eigen::VectorXcd as state type, to solve a huge linear ODE system. In that project, the matrix in the ODE system is sparse. Multiplying a it with a dense vector can be computed in parallel in a simple way using Eigen. However, I have faced some problems in that situation that I will tell in details below. Currently I am applying a not-so efficient solution, namely, I use arma::cx_vec as state type, and declare the matrix corresponding

How to make two sliders in matplotlib

守給你的承諾、 提交于 2019-12-31 02:57:31
问题 I would like to make two sliders in matplotlib to manually change N and P values in my predator-prey model: import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint def lotka(x,t,params): N, P = x alpha, beta, gamma, delta = params derivs = [alpha*N - beta*N*P, gamma*N*P - delta*P] return derivs N=2 P=1 alpha=3 beta=0.5 gamma=0.4 delta=3 params = [alpha, beta, gamma, delta] x0=[N,P] maxt = 20 tstep = 0.01 t=np.arange(0,maxt,tstep) equation=odeint(lotka, x0, t,

Problems with a function and odeint in python

不问归期 提交于 2019-12-25 08:49:45
问题 For a few months I started working with python, considering the great advantages it has. But recently, i used odeint from scipy to solve a system of differential equations. But during the integration process the implemented function doesn't work as expected. In this case, I want to solve a system of differential equations where one of the initial conditions (x[0]) varies (between 4-5) depending on the value that the variable reaches during the integration process (It is programmed inside of

Odeint function from scipy.integrate gives wrong result

烈酒焚心 提交于 2019-12-25 03:44:45
问题 I use odeint function to solve a coupled differential equations system and plot one of the variables (theta_i) after the system is solved. My variable (theta_i) comes from the equation: theta_i = np.arctan2(g1,g2) where g1 ang g2 are variables calculated in the same function. The results have to be between -pi and pi and they are supposed to look like this (plot from matlab simulation): However, when I try to plot theta_i after odeint has finished I get this(plot from my python code): which

odeint returns wrong results for an ODE including descrete function

妖精的绣舞 提交于 2019-12-25 01:44:57
问题 I'm trying to model the ODE: I implemented: import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt m = 1 k = 1 M = 0.1 b = 1 Fmax = 1 def dXdt(X,t): return [X[1], - b * X[1] / m - k * X[0] / m - M * np.sign(X[1]) / m + Fmax / m ] X0 = [1, 2] ts = np.linspace(0, 10, 200) Xs = odeint(dXdt, X0, ts) plt.plot(ts, Xs[:, 0]) resulting: which contradicts what I get from Modelica (OpenModelica): model model1 //constants parameter Real m = 1; parameter Real k = 1;

Boost odeint class with derivative and jacobian

霸气de小男生 提交于 2019-12-24 04:22:32
问题 I intend to use the Boost odeint library in an MCMC routine to estimate parameters in an ODE model. Since these ODEs may be stiff, I need to be able to pass the jacobian into the solver with the derivative. I would like to make a class which has the parameters and initial values as private members and then the derivative, jacobian, and methods to change the parameters as public methods. I tried to modify the stiff example from the odeint website to use one class containing both, but am

Python's multiprocessing: speed up a for-loop for several sets of parameters, “apply” vs. “apply_async”

本小妞迷上赌 提交于 2019-12-24 03:30:00
问题 I would like to integrate a system of differential equations using a lot of different parameter combinations and store the variables’ final values that belong to a certain set of parameters. Therefore, I implemented a simple for-loop in which random initial conditions and parameter combinations are created, the system is integrated and the values of interest are stored in the respective arrays. Since I intend to do this for many parameter combinations for a rather complex system (here I only