ode

need to understand better how rtol, atol work in scipy.integrate.odeint

为君一笑 提交于 2019-12-04 11:56:36
Here scipy.integrate.odeint is called with six different standard ode problems with rtol = atol from 1E-06 to 1E-13 . I've looked at the max difference between the results at all larger tolerances minus those of the smallest, to get some kind of representation of "error". I'm curious why, for a given tolerance, one problem (D5) gives errors a million times worse than another problem (C1), even though the range in number of steps is fairly tight (within a factor of 10). The citation for the ode problems is given in the script. All problems are fairly well normalized so I'm treating rtol and

Solve ode in python with complex matrix as initial value

喜夏-厌秋 提交于 2019-12-04 10:16:28
I have a von Neumann equation which looks like: dr/dt = - i [H, r] , where r and H are square matricies of complex numbers and I need to find r(t) using python script. Is there any standart instruments to integrate such equations? When I was solving another aquation with a vector as initial value, like Schrodinger equation: dy/dt = - i H y , I used scipy.integrate.ode function ('zvode'), but trying to use the same function for von Neumann equation gives me the following error: **scipy/integrate/_ode.py:869: UserWarning: zvode: Illegal input detected. (See printed message.) ZVODE-- ZWORK length

solving two dimension-differential equations in python with scipy

帅比萌擦擦* 提交于 2019-12-03 21:51:18
i am a newbie to python. I have a simple differential systems, which consists of two variables and two differential equations and initial conditions x0=1, y0=2 : dx/dt=6*y dy/dt=(2t-3x)/4y now i am trying to solve these two differential equations and i choose odeint . Here is my code: import matplotlib.pyplot as pl import numpy as np from scipy.integrate import odeint def func(z,b): x, y=z return [6*y, (b-3*x)/(4*y)] z0=[1,2] t = np.linspace(0,10,11) b=2*t xx=odeint(func, z0, b) pl.figure(1) pl.plot(t, xx[:,0]) pl.legend() pl.show() but the result is incorrect and there is a error message:

complex ODE systems in scipy

南楼画角 提交于 2019-12-03 20:12:23
I am having trouble sovling the optical bloch equation, which is a first order ODE system with complex values. I have found scipy may solve such system, but their webpage offers too little information and I can hardly understand it. I have 8 coupled first order ODEs, and I should generate a function like: def derv(y): compute the time dervative of elements in y return answers as an array then do complex_ode(derv) My questions are: my y is not a list but a matrix, how can i give a corrent output fits into complex_ode()? complex_ode() needs a jacobian, I have no idea how to start constructing

Solve an implicit ODE (differential algebraic equation DAE)

倖福魔咒の 提交于 2019-12-03 13:42:51
问题 I'm trying to solve a second order ODE using odeint from scipy. The issue I'm having is the function is implicitly coupled to the second order term, as seen in the simplified snippet (please ignore the pretend physics of the example): import numpy as np from scipy.integrate import odeint def integral(y,t,F_l,mass): dydt = np.zeros_like(y) x, v = y F_r = (((1-a)/3)**2 + (2*(1+a)/3)**2) * v # 'a' implicit a = (F_l - F_r)/mass dydt = [v, a] return dydt y0 = [0,5] time = np.linspace(0.,10.,21) F

ODEs with infinite initlal condition in python

只愿长相守 提交于 2019-12-03 09:08:40
I have a second order differential equation that I want to solve it in python. The problem is that for one of the variables I don't have the initial condition in 0 but only the value at infinity. Can one tell me what parameters I should provide for scipy.integrate.odeint ? Can it be solved? Equation: Theta needs to be found in terms of time. Its first derivative is equal to zero at t=0 . theta is not known at t=0 but it goes to zero at sufficiently large time. all the rest is known. As an approximate I can be set to zero, thus removing the second order derivative which should make the problem

How to solve this differential equation using scipy odeint?

别等时光非礼了梦想. 提交于 2019-12-02 10:21:50
问题 I am trying to solve the following differential equation using scipy odeint without much success: import numpy as np from scipy.misc import derivative from scipy.integrate import odeint Imag = 16000. w = 2*np.pi*60 tau = .05 theta = 1.52 phi = theta - np.radians(90) t = np.linspace(0,.1,10000) def Ip(t): return np.sqrt(2)*Imag*(np.sin(w*t+phi-theta)-np.exp(-t/tau)*np.sin(phi-theta)) B = lambda Ip: Ip/(53.05+0.55*abs(Ip)) def L(B): return derivative(B,Ip(t))*377.2 def dI(t): return derivative

setup odes in python

China☆狼群 提交于 2019-12-02 08:51:51
问题 how to setup the following odes with the corresponding initial conditions in python? x'(t) =x(t) - y(t) - e^t y'(t) =x(t) + y(t) + 2e^t with x(0)= -1 and y(0)= -1 and 0 <= t <= 4 The following is what I have so far: def f(u, t): x, y = u return [x+y-e**t, x+y+2*e**t] x0, y0 = [-1.0,-1.0] t = numpy.linspace( 0,4,50 ) 回答1: I guess you're trying to solve them with odeint. First I'm assuming you use this prelude in you script : import numpy as np from scipy.integrate import odeint Your equation

Error : 'x' undefined

浪子不回头ぞ 提交于 2019-12-02 07:51:05
问题 I got a problem with running Octave function (ODE), I've tried already present solutions for this problem but nothing is working. I've also tried by saving my filename as egzamin.m but it too not worked. Code from octave : function dx=egzamin(x,t) dx=zeros(4,1); b=0; g=9.81; x1=x(1); y1=x(2); Vx=x(3); Vy=x(4); dx(1)=Vx; dx(2)=Vy; dx(3)=-b*Vx*sqrt(Vx.^2+Vy.^2); dx(4)=-b*Vy*sqrt(Vx.^2+Vy.^2)-g; endfunction N=mod(291813,100); x1=0; y1=0; Vx=20+N; Vy=20+N; t=0:0.01:500; sol=lsode("egzamin",[x1,y1

solving two uncoupled ODEs within a loop using python and scipy.integrate.ode

随声附和 提交于 2019-12-02 04:56:09
问题 I am having problem for solving two very easy uncoupled ODEs using scipy.integrate.ode. For instance this following simple code: from scipy.integrate import ode def f(t, y, r_r=1.68,mu_ext=0. ,tau_m=0.020, tau_s=0.005, gs= 0.5): dmu = (1./tau_s)*(-y[0] + mu_ext + gs*r_r) dx = (1./tau_m)*(-y[1] + y[0]) return [dmu, dx] t0 = 0.0 #Intial time y0 = [4.0, 0.0] #initial condition for x = 0 y1 = [4.0, 1.0] #inital condition for x = 1 x0m = ode(f) x0m.set_initial_value(y0, t0) x1m = ode(f) x1m.set