Python – Solving First Order Differential Equations

Dwight Reid

This presentation outlines how to solve an ordinary differential equation (ode) with python. The solution is obtained numerically using the python scipy ode engine (integrate module), the solution is therefore not in analytic form but the output as if the analytic function was computed for each time step. We will use a series RC circuit for our example.

Slide Show

Python Code

# -*- coding: utf-8 -*-
from scipy import integrate
from pylab import *

def capVolts(Vc,t): # f(x) function
    V = 12
    R = 0.5
    C = 1
    return (V-Vc)/(R*C)

time = linspace(0.0,5.0,1000)
y = integrate.odeint(capVolts,0,time)


Differential Equations – Python

Return Home