Skip to content

Tools for plotting behavior of differential equations

An answer to this question on the Mathematics Stack Exchange.

Question

I have several ODEs describing the behavior of dividing particles (e.g., https://math.stackexchange.com/questions/84155/how-to-model-multi-step-cell-differentiation). I would like to plot these ODEs based on changing values of p over time. I would appreciate any advice on what graphics program would be suitable for this task.

Thanks.

Answer

Python is a flexible way of doing this, à la:

#!/usr/bin/env python3
import scipy.integrate
import matplotlib.pyplot as plt
import numpy as np
def func(p, t):
  """Takes a vector p representing the current state and the time t"""
  pdot = 0.2*[0]**0.75
  return [pdot]
t    = np.linspace(0, 100, 200)              #Return state at these time points
init = [2]                                   #Initial conditions
z    = scipy.integrate.odeint(func, init, t) #Integrate the ODE
z    = z.T[0]                                #Transpose and extract state
plt.plot(t,z)
plt.show()