differential-equations

Solve ODE in Python with a time-delay

北城以北 提交于 2019-11-30 22:52:20
Can anybody give me some advice how to solve an ODE in Python that has a time-delay implemented in it? I can't seem to figure out how to do it using scipy.integrate.odeint. What I am looking for should look like: # the constants in the equation b = 1/50 d = 1/75 a = 0.8 G = 10 ** (-2) tau = 0.5 u = [b, d, tau, a, G] # enter initial conditions N0 = 0.1 No0 = 10 w = [N0, No0] def logistic(w, t, u): N, No = w b, d, tau, a, G = u dNdt = b * (No(t) - N(t) ) * (N(t) / No(t) ) - d * N(t - tau) dNodt = G * (a * No(t) - N(t) ) * (N(t) / No(t) ) return [dNdt, dNodt] # create timescale # create timescale

plotting orbital trajectories in python

末鹿安然 提交于 2019-11-30 21:53:32
How can I setup the three body problem in python? How to I define the function to solve the ODEs? The three equations are x'' = -mu / np.sqrt(x ** 2 + y ** 2 + z ** 2) * x , y'' = -mu / np.sqrt(x ** 2 + y ** 2 + z ** 2) * y , and z'' = -mu / np.sqrt(x ** 2 + y ** 2 + z ** 2) * z . Written as 6 first order we have x' = x2 , y' = y2 , z' = z2 , x2' = -mu / np.sqrt(x ** 2 + y ** 2 + z ** 2) * x , y2' = -mu / np.sqrt(x ** 2 + y ** 2 + z ** 2) * y , and z2' = -mu / np.sqrt(x ** 2 + y ** 2 + z ** 2) * z I also want to add in the path Plot o Earth's orbit and Mars which we can assume to be circular.

Solve ODE in Python with a time-delay

北战南征 提交于 2019-11-30 15:48:40
问题 Can anybody give me some advice how to solve an ODE in Python that has a time-delay implemented in it? I can't seem to figure out how to do it using scipy.integrate.odeint. What I am looking for should look like: # the constants in the equation b = 1/50 d = 1/75 a = 0.8 G = 10 ** (-2) tau = 0.5 u = [b, d, tau, a, G] # enter initial conditions N0 = 0.1 No0 = 10 w = [N0, No0] def logistic(w, t, u): N, No = w b, d, tau, a, G = u dNdt = b * (No(t) - N(t) ) * (N(t) / No(t) ) - d * N(t - tau) dNodt

Numerical ODE solving in Python

戏子无情 提交于 2019-11-30 05:04:38
How do I numerically solve an ODE in Python? Consider \ddot{u}(\phi) = -u + \sqrt{u} with the following conditions u(0) = 1.49907 and \dot{u}(0) = 0 with the constraint 0 <= \phi <= 7\pi. Then finally, I want to produce a parametric plot where the x and y coordinates are generated as a function of u. The problem is, I need to run odeint twice since this is a second order differential equation. I tried having it run again after the first time but it comes back with a Jacobian error. There must be a way to run it twice all at once. Here is the error: odepack.error: The function and its Jacobian

Solving the Lorentz model using Runge Kutta 4th Order in Python without a package

筅森魡賤 提交于 2019-11-29 12:15:25
I wish to solve the Lorentz model in Python without the help of a package and my codes seems not to work to my expectation. I do not know why I am not getting the expected results and Lorentz attractor. The main problem I guess is related to how to store the various values for the solution of x,y and z respectively.Below are my codes for the Runge-Kutta 45 for the Lorentz model with 3D plot of solutions: import numpy as np import matplotlib.pyplot as plt #from scipy.integrate import odeint #a) Defining the Runge-Kutta45 method def fx(x,y,z,t): dxdt=sigma*(y-z) return dxdt def fy(x,y,z,t): dydt

How to evaluate the constants SymPy gives with initial condition?

十年热恋 提交于 2019-11-29 07:56:21
How can I evaluate the constants C1 and C2 from a solution of a differential equation SymPy gives me? There are the initial condition f(0)=0 and f(pi/2)=3. >>> from sympy import * >>> f = Function('f') >>> x = Symbol('x') >>> dsolve(f(x).diff(x,2)+f(x),f(x)) f(x) == C1*sin(x) + C2*cos(x) I tried some ics stuff but it's not working. Example: >>> dsolve(f(x).diff(x,2)+f(x),f(x), ics={f(0):0, f(pi/2):3}) f(x) == C1*sin(x) + C2*cos(x) By the way: C2 = 0 and C1 = 3. There's a pull request implementing initial/boundary conditions, which was merged and should be released in SymPy 1.2. Meanwhile, one

Numerical ODE solving in Python

假如想象 提交于 2019-11-29 02:47:05
问题 How do I numerically solve an ODE in Python? Consider \ddot{u}(\phi) = -u + \sqrt{u} with the following conditions u(0) = 1.49907 and \dot{u}(0) = 0 with the constraint 0 <= \phi <= 7\pi. Then finally, I want to produce a parametric plot where the x and y coordinates are generated as a function of u. The problem is, I need to run odeint twice since this is a second order differential equation. I tried having it run again after the first time but it comes back with a Jacobian error. There must

Need help solving a second order non-linear ODE in python

强颜欢笑 提交于 2019-11-28 23:43:56
I don't really know where to start with this problem, as I haven't had much experience with this but it is required to solve this part of the project using a computer. I have a 2nd order ODE which is: m = 1220 k = 35600 g = 17.5 a = 450000 and b is between 1000 and 10000 with increments of 500. x(0)= 0 x'(0)= 5 m*x''(t) + b*x'(t) + k*x(t)+a*(x(t))^3 = -m*g I need to find the smallest b such that the solution is never positive. I know what the graph should look like, but I just don't know how to use odeint to get a solution to the differential equation. This is the code I have so far: from

Differential Equations in Python [closed]

匆匆过客 提交于 2019-11-28 17:34:42
I'm working with a DE system, and I wanted to know which is the most commonly used python library to solve Differential Equations if any. My Equations are non Linear First Order equations. If you need to solve large nonlinear systems (especially stiff ones), the scipy tools will be slow and awkward. The PyDSTool package is now quite commonly used in this situation. It lets your equations be automatically converted into C code and integrates them with good solvers. It's especially good if you want to define state-defined events such as threshold crossings, add external input signals from arrays

How can I use Cython well to solve a differential equation faster?

会有一股神秘感。 提交于 2019-11-28 04:33:38
问题 I would like to lower the time Scipy's odeint takes for solving a differential equation. To practice, I used the example covered in Python in scientific computations as template. Because odeint takes a function f as argument, I wrote this function as a statically typed Cython version and hoped the running time of odeint would decrease significantly. The function f is contained in file called ode.pyx as follows: import numpy as np cimport numpy as np from libc.math cimport sin, cos def f(y, t,