Questions tagged [differential-equations]

An equation that relates some unknown function itself and its derivatives of various orders.

An equation that relates some unknown function itself and its derivatives of various orders, for instance x'' = g (free fall) or x' = v (movement under constant speed). Developers solve differential equations numerically or write symbolic engines to solve analytically.

1488 questions
8
votes
2 answers

non linear regression with random effect and lsoda

I am facing a problem I do not manage to solve. I would like to use nlme or nlmODE to perform a non linear regression with random effect using as a model the solution of a second order differential equation with fixed coefficients (a damped…
denis
  • 5,580
  • 1
  • 13
  • 40
8
votes
1 answer

How does odeint() from scypy python module work?

I am a physics student interested in solving ODEs numerically. I usually write my own solvers in C using Runge–Kutta methods. I recently learned Python, and I used SciPy’s odeint function to solve ODEs. But I am worried about how the function…
8
votes
4 answers

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

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…
fabian
  • 1,413
  • 1
  • 13
  • 24
8
votes
2 answers

How to find the nth derivative given the first derivative with SymPy?

Given some f and the differential equation x'(t) = f(x(t)), how do I compute x(n)(t) in terms of x(t)? For example, given f(x(t)) = sin(x(t)), I want to obtain x(3)(t) = (cos(x(t))2 − sin(x(t))2) sin(x(t)). So far I've tried >>> from sympy import…
user541686
  • 205,094
  • 128
  • 528
  • 886
8
votes
1 answer

How to solve differential equation using Python builtin function odeint?

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 =…
Physicist
  • 2,848
  • 8
  • 33
  • 62
7
votes
1 answer

Solve the Heat Equation with non-zero Dirichlet BCs with Implicit Euler and Conjugate Gradient Linear Solvers?

Many users have asked how to solve the Heat Equation, u_t = u_xx, with non-zero Dirichlet BCs and with conjugate gradients for the internal linear solver. This is a common simplified PDE problem before moving to more difficult versions of parabolic…
7
votes
2 answers

Application of Boundary Conditions in finite difference solution for the heat equation and Crank-Nicholson

The code below solves the 1D heat equation that represents a rod whose ends are kept at zero temparature with initial condition 10*np.sin(np.pi*x). How are the Dirichlet boundary conditions (zero temp at both ends) worked into this calculation? I…
BBSysDyn
  • 4,389
  • 8
  • 48
  • 63
7
votes
3 answers

Imitate ode45 function from MATLAB in Python

I am wondering how to export MATLAB function ode45 to python. According to the documentation is should be as follows: MATLAB: [t,y]=ode45(@vdp1,[0 20],[2 0]); Python: import numpy as np def vdp1(t,y): dydt=…
Migui Mag
  • 187
  • 1
  • 3
  • 13
7
votes
1 answer

Solve ODE in Python with a time-delay

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 =…
ThePiIsALie
  • 71
  • 1
  • 4
7
votes
1 answer

Solving a system of differential equations in R

I have a simple flux model in R. It boils down to two differential equations that model two state variables within the model, we'll call them A and B. They are calculated as simple difference equations of four component fluxes flux1-flux4, 5…
colin
  • 2,606
  • 4
  • 27
  • 57
7
votes
4 answers

Haskell - Optimizing differential equation solver

I'm learning Haskell and am trying to write code as fast as I can do in C. For this exercise, I'm writing a Euler integrator for a simple one-dimensional physical system. The C code is compiled with GCC 4.5.4 and -O3. It runs in 1.166 seconds. The…
Charles Welton
  • 841
  • 7
  • 14
6
votes
3 answers

Solving a delay differential equation (DDE) system constrained to give nonnegative solutions

In MATLAB, ode45 has a parameter called NonNegative which constrains the solutions to be nonnegative. They even wrote a paper about how this method works and how it's not something as stupid as just setting y_i to 0 whenever it becomes negative, as…
6
votes
1 answer

Is there an idiomatic way to terminate integration after n callbacks in DifferentialEquations.jl

First of all, I am using the DifferentialEquations.jl library, which is fantastic! Anyway, my question is as follows: Say for example, I have the following differential equation: function f(du, u, t) du[1] = u[3] du[2] = u[4] du[3] =…
Rolfe Power
  • 138
  • 1
  • 5
6
votes
2 answers

python: Initial condition in solving differential equation

I want to solve this differential equation: y′′+2y′+2y=cos(2x) with initial conditions: y(1)=2,y′(2)=0.5 y′(1)=1,y′(2)=0.8 y(1)=0,y(2)=1 and it's code is: import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt def…
6
votes
1 answer

Ordinary differential equations (ODEs) - Is there any way to prevent negative values?

I am trying to apply a system of ordinary differential equations (ODEs) at each spatial grid cell. Thus, each landscape cell has an associated ODE model. The number of susceptible mosquitoes (Sv), exposed mosquitoes (Se) and infected mosquitoes (St)…
Nell
  • 559
  • 4
  • 20