odeint

Differences between two ODE solvers

混江龙づ霸主 提交于 2021-01-27 11:27:37
问题 I am wondering, what are the differences between ODEINT and solve_ivp for solving a differential equation. What could be advantages and disadvantages between them? f1 = solve_ivp(f, [0,1], y0) #y0 is the initial point f2 = odeint(f, y0, [0, 1], args=(a, b)) # a and b are arguments of function f Thank you 回答1: Well the main difference is the following: odeint came first and is uses lsoda from the FORTRAN package odepack to solve ODEs. solve_ivp is a more general solution that lets use decide

Differences between two ODE solvers

半腔热情 提交于 2021-01-27 11:25:12
问题 I am wondering, what are the differences between ODEINT and solve_ivp for solving a differential equation. What could be advantages and disadvantages between them? f1 = solve_ivp(f, [0,1], y0) #y0 is the initial point f2 = odeint(f, y0, [0, 1], args=(a, b)) # a and b are arguments of function f Thank you 回答1: Well the main difference is the following: odeint came first and is uses lsoda from the FORTRAN package odepack to solve ODEs. solve_ivp is a more general solution that lets use decide

Python odeint with array in differential equation

淺唱寂寞╮ 提交于 2020-06-23 13:37:29
问题 I have next first order differential equation (example): dn/dt=A*n; n(0)=28 When A is constant, it is perfectly solved with python odeint. But i have an array of different values of A from .txt file [not function,just an array of values] A = [0.1,0.2,0.3,-0.4,0.7,...,0.0028] And i want that in each iteration (or in each moment of time t ) of solving ode A is a new value from array. I mean that: First iteration (or t=0) - A=0.1 Second iteration (or t=1) - A=0.2 and etc from array. How can i do

How to use if-else statement for solving a system of differential equations using odeint?

人走茶凉 提交于 2020-03-25 12:31:42
问题 I'm trying to use odeint to solve a system of equations in state-space form using odeint .when I run this code, I just get the plot for one condition only. import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt from numpy import zeros X=np.array([[0],[0],[0],[0]]) X1=np.array([[0],[0],[0],[0]]) U= np.array([[vin],[vdon]]) defining A1,A0,B1,B0 def conv(X,t): sw=0 if condition statement else: statement return xdot X0=np.array([0,0,0,0]) t=np.arange(0,.0005,10**-8)

DDE using boost odeint

孤者浪人 提交于 2020-02-28 08:30:52
问题 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. 回答1: 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

ODEint: adaptive integration with arbitrary precision

你说的曾经没有我的故事 提交于 2020-01-24 09:47:27
问题 Is it possible for ODEint to use adaptive integration routines with arbitrary precision arithmetic? For example, I'd like to use the Boost multiprecision libraries with the integrate_adaptive() function with a controlled stepper. The ODEint documentation gives examples for using arbitrary precision arithmetic for integrate_const(), but I can't modify them to use the adaptive integrator. I've also tried using iterators (e.g. make_adaptive_time_iterator...) but run into similar problems. For

Plotting a solution and its derivative, of a first order ODE

跟風遠走 提交于 2020-01-16 07:58:12
问题 I have this code to solve a simple first order ODE using odeint. I managed to plot the solution y(r), but I also want to plot the derivative y'= dy/dr. I know y' it is given by f(y,r), but I'm not sure how to call the function with the output of the integration. Thank you in advance. from math import sqrt from numpy import zeros,linspace,array from scipy.integrate import odeint import matplotlib.pylab as plt def f(y,r): f = zeros(1) f[0] = -(y[0]*(y[0]-1.0)/r)-y[0]*(2/r+\ ((r/m)/(1-r**2/m))*

scipy odeint with complex initial values

帅比萌擦擦* 提交于 2020-01-13 18:55:13
问题 I need to solve a complex-domain-defined ODE system, with complex initial values. scipy.integrate.odeint does not work on complex systems. I rod about cutting my system in real and imaginary part and solve separately, but my ODE system's rhs involves products between dependent variables themselves and their complex conjugates. Haw do I do that? Here is my code, I tried breaking RHS in Re and Im parts, but I don't think the solution is the same as if I wouldn't break it because of the internal

How to solve differential equation using Python builtin function odeint?

情到浓时终转凉″ 提交于 2020-01-11 05:25:08
问题 I want to solve this differential equations with the given initial conditions: (3x-1)y''-(3x+2)y'+(6x-8)y=0, y(0)=2, y'(0)=3 the ans should be y=2*exp(2*x)-x*exp(-x) here is my code: def g(y,x): y0 = y[0] y1 = y[1] y2 = (6*x-8)*y0/(3*x-1)+(3*x+2)*y1/(3*x-1) return [y1,y2] init = [2.0, 3.0] x=np.linspace(-2,2,100) sol=spi.odeint(g,init,x) plt.plot(x,sol[:,0]) plt.show() but what I get is different from the answer. what have I done wrong? 回答1: There are several things wrong here. Firstly, your

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

前提是你 提交于 2020-01-05 05:20:18
问题 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