odeint

How to get SciPy.integrate.odeint to stop when path is closed?

天涯浪子 提交于 2019-12-07 04:44:24
问题 The script below integrates magnetic field lines around closed paths and stops when it returns to original value within some tolerance, using Runge-Kutta RK4 in Python. I would like to use SciPy.integrate.odeint , but I can not see how I can tell it to stop when the path is approximately closed. Of course odeint may be much faster than integrating in Python, I could just let it go around blindly and look for closure in the results, but in the future I'll do much larger problems. Is there a

Can I integrate with scipy's odeint until a local max is found?

不羁的心 提交于 2019-12-06 05:51:21
问题 This is my first question on here, so please go easy on me. I'm wondering if there is a way to integrate an ODE system only until a local max of a specified variable is found. Here is some more detail: Let's call our ODE system dX/dt = F(X) where X(t) = [x1(t), x2(t), ... , xn(t)] . Assume the solution to this system is attracted to a stable limit cycle C everywhere but at one unstable fixed point p. Choose some initial conditions X0 not p, and not in C. We wish to follow the trajectory of

Why isn't the Dfunc(gradient) called while using integrate.odeint in SciPy?

心已入冬 提交于 2019-12-05 20:21:43
问题 Can anyone provide an example of providing a jacobian to a integrate.odeint function in SciPy?. I try to run this code from SciPy tutorial odeint example but seems that Dfunc (gradient) is never called. from numpy import * # added from scipy.integrate import odeint from scipy.special import gamma, airy y1_0 = 1.0/3**(2.0/3.0)/gamma(2.0/3.0) y0_0 = -1.0/3**(1.0/3.0)/gamma(1.0/3.0) y0 = [y0_0, y1_0] def func(y, t): return [t*y[1],y[0]] def gradient(y,t): print 'jacobian' # added return [[0,t],

DDE using boost odeint

删除回忆录丶 提交于 2019-12-05 18:50:21
Is it possible to solve a time delay differential equations using C++ Boost - odeint library ? For an instance below equation: x'(t) = r*x(t)*(1 - x(t-tau)), where tau is a constant value for time delay. Yes, you can. But odeint is not explicitly designed for DDEs. There are two possibilities to solve DDEs with odeint: You consider x and its discretized history as dependend variables and use directly the steppers. You consider only x as dependent variable and pass the history with the system function (your r.h.s.). But in this case you should only use steppers which evaluate the state at

Stop integration in odeint with stiff ode

五迷三道 提交于 2019-12-04 18:14:15
I want to solve a stiff ode with odeint. I was following this (rosenbrock4_dense_output stepper) but, my function can grow pretty quickly so I want to stop the integration if x(t)>xMAX. In this question , they have a solution for it but since I'm new with c++ I don't know how to implement this when using a rosenbrock4_dense_output stepper. I would like to see how to write this specifically for rosenbrock4_dense_output stepper. Currently, this is not easily possible with odeint. If you can use the range library here you can combine a for_each and a find_if algorithm. Otherwise you need to write

Solving Matrix Differential Equation in Python using Scipy/Numpy- NDSolve equivalent?

江枫思渺然 提交于 2019-12-04 14:38:32
I have two numpy arrays: 9x9 and 9x1. I'd like to solve the differential equation at discrete time points, but am having trouble getting ODEInt to work. I do am unsure if I'm even doing the right thing. With Mathematica, the equation is: Solution = {A[t]} /. NDSolve[{A'[t] == Ab.A[t] && A[0] == A0}, {A[t]}, {t, 0, .5}, MaxSteps -> \[Infinity]]; time = 0.25; increment = 0.05; MA = Table[Solution, {t, 0, time, increment}]; Where Ab is the 9x9 matrix, A0 is the 9x1 matrix (initial). Here, I solve for time and life is good. In Python implementation I have the following code which gives me the

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

时光毁灭记忆、已成空白 提交于 2019-12-04 12:06:37
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 the ode arma::cx_mat, which is a dense matrix type. Unfortunately, sparse-matrix-dense vector

Why isn't the Dfunc(gradient) called while using integrate.odeint in SciPy?

跟風遠走 提交于 2019-12-04 03:04:34
Can anyone provide an example of providing a jacobian to a integrate.odeint function in SciPy?. I try to run this code from SciPy tutorial odeint example but seems that Dfunc (gradient) is never called. from numpy import * # added from scipy.integrate import odeint from scipy.special import gamma, airy y1_0 = 1.0/3**(2.0/3.0)/gamma(2.0/3.0) y0_0 = -1.0/3**(1.0/3.0)/gamma(1.0/3.0) y0 = [y0_0, y1_0] def func(y, t): return [t*y[1],y[0]] def gradient(y,t): print 'jacobian' # added return [[0,t],[1,0]] x = arange(0,4.0, 0.01) t = x ychk = airy(x)[0] y = odeint(func, y0, t) y2 = odeint(func, y0, t,

Canot compile C++ which uses odeint from boost

左心房为你撑大大i 提交于 2019-12-02 17:23:18
问题 I'm on Ubuntu 12.04 & had some boost fies already in /usr/include. I did a sudo apt-get install libboost-all-dev and that installed a lot of files too. I don't want to remove this boost and install from source as several other packages depend on the version from the ubuntu repos. This is the sample code I want to run :- #include <iostream> #include <boost/numeric/odeint.hpp> using namespace std; using namespace boost::numeric::odeint; typedef vector< double > state_type; const double sigma =

System of differential equations with time dependent constants in arrays, using odeint

大兔子大兔子 提交于 2019-12-02 15:56:06
问题 Let's say that I have a system of differential equations and I want to solve it with odeint. Some of the system's constants are time depended and I have their values stored in arrays (a,b,c and d with shape (8000, ) ). I want the system to use a different value of these constants at each time step. See the simplified code example: t = np.linspace(0,100,8000) a = np.array([0, 5, 6, 12, 1.254, ..., 0.145]) # shape (8000, ) b = np.array([1.45, 5.9125, 1.367, ..., 3.1458]) c = np.array([0.124, 0