Python ODE Solver

less than 1 minute read

First Order RC Model

A resistor and capacitor in parallel model:

import scipy.integrate as integrate
import matplotlib.pyplot as plt
import numpy as np

t = np.linspace(0.0, 10e-3, 1000)

# Parallel RC Model
R = 100
C = 10e-6
v_init = [10]
v = integrate.odeint(lambda v, t: -v/(R*C), v_init, t)

fig, ax = plt.subplots()
ax.plot(t, v)

Second Order RCL Model

A resistor, capacitor and inductor in parallel model:

import scipy.integrate as integrate
import matplotlib.pyplot as plt
import numpy as np

t = np.linspace(0.0, 10e-3, 1000)

# Parallel RCL Model
R = 100
C = 10e-6
L = 12e-3
v_init = [10.0, 0.0]
v = integrate.odeint(
    lambda v, t: [v[1], -v[1]/(R * C) - v[0]/(C * L)],
    v_init, t)

fig, ax = plt.subplots()
ax.plot(t, v[:, 0])
plt.show()