1
Instructor:
Welcome to BME 603/606�
Computational Methods for�Biological Modeling & Simulation
Assistant Professor of Biomedical Engineering�Affiliate, Data Science Institute�Affiliate, Biophysics Graduate Program�Affiliate, Center for Genomic Science Innovation�Affiliate, Wisconsin Institute for Translational Neuroengineering �University of Wisconsin-Madison
DHANANJAY ‘Jay’ BHASKAR
Course Website: https://bio-modeling-uw-madison-f26.github.io/
2
BME 603/606: Computational Methods for Biological Modeling & Simulation
Announcements / Reflection
3
BME 603/606: Computational Methods for Biological Modeling & Simulation
Numerical Integration
Oral absorption model
• C(t) measured at discrete time points, no closed form
• Must approximate the integral numerically
4
BME 603/606: Computational Methods for Biological Modeling & Simulation
Trapezoidal Rule
Use two nodes: the endpoints a and b
Approximate:
Error (single interval):
• Precision: ρ = 1 (exact for polynomials of degree ≤ 1)
• Accuracy: O(h2)
a
b
5
BME 603/606: Computational Methods for Biological Modeling & Simulation
Midpoint Rule
Use one node: the midpoint m = (a + b) / 2
Approximate:
Error (single interval):
• Precision: ρ = 1 (same as trapezoid)
• Accuracy: O(h2)
a
b
f((a+b)/2)
6
BME 603/606: Computational Methods for Biological Modeling & Simulation
Simpson's Rule
Use three nodes: endpoints a, b and midpoint m = (a + b)/2
Approximate:
Error (single interval):
• Precision: ρ = 3 (exact for polynomials of degree ≤ 3)
• Accuracy: O(h4)
a
b
f((a+b)/2)
7
BME 603/606: Computational Methods for Biological Modeling & Simulation
Simpson's Rule
Use three nodes: endpoints a, b and midpoint m = (a + b)/2
Approximate:
• Fits a parabola through (a,f(a)), (m,f(m)), (b,f(b))
• integrates the parabola exactly
• weights: 1/6, 4/6, 1/6 � (endpoints less, midpoint more)
a
b
f((a+b)/2)
8
BME 603/606: Computational Methods for Biological Modeling & Simulation
Composite Methods
Subdivide [a, b] into r sub-intervals, h = (b-a)/r, with nodes t₀, t₁, ..., tᵣ
Composite Trapezoidal Rule:
Composite Simpson's Rule (r must be even):
halving h reduces error by 4x (trapezoidal) or 16x (Simpson's)
9
BME 603/606: Computational Methods for Biological Modeling & Simulation
Python Implementation
import numpy as np
t = np.array([0.0, 0.5, 1.0, 2.0, 4.0, 8.0, 12.0, 24.0]) # hr
C = np.array([0.0, 45.0, 82.0, 134.0, 98.0, 55.0, 28.0, 6.0]) # ng/mL
# Composite trapezoidal (handles non-uniform spacing)
AUC_trap = np.trapz(C, t)
print(f"AUC (trapz): {AUC_trap:.1f} ng*hr/mL")
# Composite Simpson on uniform grid (r must be even)
t_f = np.linspace(0, 24, 100)
C_f = np.interp(t_fine, t, C) # replace with your own interp method
h = t_f[1] - t_f[0]
AUC_simp = h/3*(C_f[0] + 4*sum(C_f[1:-1:2]) + 2*sum(C_f[2:-2:2]) + C_f[-1])
print(f"AUC (Simpson): {AUC_simp:.1f} ng*hr/mL")
10
BME 603/606: Computational Methods for Biological Modeling & Simulation
Lagrange Basis Quadrature
Idea: interpolate f(x) by a polynomial, then integrate that polynomial exactly.
Lagrange interpolant through nodes x₀, ..., xₙ:
Integrating gives a weighted sum (quadrature rule):
(precomputed weights)
11
BME 603/606: Computational Methods for Biological Modeling & Simulation
scipy.integrate.quad
from scipy.integrate import quad
import numpy as np
ka, ke = 1.2, 0.15 # absorption and elimination rates (1/hr)
F_dose = 500 # mg (bioavailable dose)
def C_plasma(t):
return F_dose * ka / (ka - ke) * (np.exp(-ke*t) - np.exp(-ka*t))
# Compute AUC from 0 to 24 hours
AUC, err = quad(C_plasma, 0, 24)
print(f"AUC (quad): {AUC:.2f} ng*hr/mL")
print(f"Error estimate: {err:.2e} ng*hr/mL")
# AUC to infinity: quad(C_plasma, 0, np.inf)
12
BME 603/606: Computational Methods for Biological Modeling & Simulation
In-Class Exercises
Please ask Colin to mark you for completion before end of class.
Course Website: https://bio-modeling-uw-madison-f26.github.io/