odeint

Comparison of odeint's runge_kutta4 with Matlab's ode45

泄露秘密 提交于 2019-11-30 22:53:27
I would like to use runge_kutta4 method in the odeint C++ library . I've solved the problem in Matlab. My following code in Matlab to solve x'' = -x - g*x' , with initial values x1 = 1 , x2 = 0 , is as follows main.m clear all clc t = 0:0.1:10; x0 = [1; 0]; [t, x] = ode45('ODESolver', t, x0); plot(t, x(:,1)); title('Position'); xlabel('time (sec)'); ylabel('x(t)'); ODESolver.m function dx = ODESolver(t, x) dx = zeros(2,1); g = 0.15; dx(1) = x(2); dx(2) = -x(1) - g*x(2); end I've installed the odeint Library. My code for using runge_kutta4 is as follows #include <iostream> #include <boost

NumPy odeint output extra variables

点点圈 提交于 2019-11-30 19:09:57
问题 What is the easiest way to save intermediate variables during simulation with odeint in Numpy? For example: def dy(y,t) x = np.rand(3,1) return y + x.sum() sim = odeint(dy,0,np.arange(0,1,0.1)) What would be the easiest way to save the data stored in x during simulation? Ideally at the points specified in the t argument passed to odeint . 回答1: A handy way to hack odeint, with some caveats, is to wrap your call to odeint in method in a class, with dy as another method, and pass self as an

odeint simple 1d ode example does not compile

試著忘記壹切 提交于 2019-11-30 18:30:53
问题 I try to run odeint examples in boost_1_54_0 on Debian Squeeze g++4.4 Lorenz system works fine, but Simple 1d ode : #include <iostream> #include <boost/numeric/odeint.hpp> using namespace std; using namespace boost::numeric::odeint; /* we solve the simple ODE x' = 3/(2t^2) + x/(2t) * with initial condition x(1) = 0. * Analytic solution is x(t) = sqrt(t) - 1/t */ void rhs( const double x , double &dxdt , const double t ) { dxdt = 3.0/(2.0*t*t) + x/(2.0*t); } void write_cout( const double &x ,

Comparison of odeint's runge_kutta4 with Matlab's ode45

柔情痞子 提交于 2019-11-30 17:27:43
问题 I would like to use runge_kutta4 method in the odeint C++ library. I've solved the problem in Matlab. My following code in Matlab to solve x'' = -x - g*x' , with initial values x1 = 1 , x2 = 0 , is as follows main.m clear all clc t = 0:0.1:10; x0 = [1; 0]; [t, x] = ode45('ODESolver', t, x0); plot(t, x(:,1)); title('Position'); xlabel('time (sec)'); ylabel('x(t)'); ODESolver.m function dx = ODESolver(t, x) dx = zeros(2,1); g = 0.15; dx(1) = x(2); dx(2) = -x(1) - g*x(2); end I've installed the

Pass args for solve_ivp (new SciPy ODE API)

不羁岁月 提交于 2019-11-30 08:43:32
For solving simple ODEs using SciPy, I used to use the odeint function, with form: scipy.integrate.odeint(func, y0, t, args=(), Dfun=None, col_deriv=0, full_output=0, ml=None, mu=None, rtol=None, atol=None, tcrit=None, h0=0.0, hmax=0.0, hmin=0.0, ixpr=0, mxstep=0, mxhnil=0, mxordn=12, mxords=5, printmessg=0)[source] where a simple function to be integrated could include additional arguments of the form: def dy_dt(t, y, arg1, arg2): # processing code here In SciPy 1.0, it seems the ode and odeint funcs have been replaced by a newer solve_ivp method. scipy.integrate.solve_ivp(fun, t_span, y0,

Optimize constants in differential equations in Python

别等时光非礼了梦想. 提交于 2019-11-29 00:43:59
Okay so how would i approach to writing a code to optimize the constants a and b in a differential equation, like dy/dt = a*y^2 + b, using curve_fit? I would be using odeint to solve the ODE and then curve_fit to optimize a and b. If you could please provide input on this situation i would greatly appreciate it! You might be better served by looking at ODEs with Sympy . Scipy/Numpy are fundamentally numerical packages and aren't really set up to do algebraic/symbolic operations. You definitely can do this: import numpy as np from scipy.integrate import odeint from scipy.optimize import curve

ODEINT with multiple parameters (time-dependent)

☆樱花仙子☆ 提交于 2019-11-28 12:39:45
问题 I'm trying to solve a single first-order ODE using ODEINT. Following is the code. I expect to get 3 values of y for 3 time-points. The issue I'm struggling with is ability to pass nth value of mt and nt to calculate dydt . I think the ODEINT passes all 3 values of mt and nt , instead just 0th, 1st or 2nd, depending on the iteration. Because of this, I get this error: RuntimeError: The size of the array returned by func (4) does not match the size of y0 (1). Interestingly, if I replace the

Multiple scipy.integrate.ode instances

一个人想着一个人 提交于 2019-11-27 03:19:16
问题 I would like to use scipy.integrate.ode (or scipy.integrate.odeint) instances in multiple threads (one for each CPU core) in order to solve multiple IVPs at a time. However the documentation says: " This integrator is not re-entrant. You cannot have two ode instances using the “vode” integrator at the same time. " (Also odeint causes internal errors if instantiated multiple times although the documentation does not say so.) Any idea what can be done? 回答1: One option is to use multiprocessing