BENG 221 Lecture 2 Tutorial BENG 221 Mathematical Methods in Bioengineering Overview Example: Ring Oscillator Dynamics Analytic ODE Solution Numerical Verification Numerical Simulation Lecture 2 Tutorial Analytic and Numerical Methods in ODEs Further Reading Gert Cauwenberghs Department of Bioengineering UC San Diego 2.1 BENG 221 Lecture 2 Tutorial Summary Overview Example: Ring Oscillator Dynamics Analytic ODE Solution Numerical Verification Numerical Simulation Further Reading We will review analytic and numerical techniques for solving ODEs, using pencil and paper, and implemented in Matlab. These simple techniques lay the foundations for solving more complex systems of PDEs in the coming weeks. By way of example we study the dynamics of a ring oscillator, a circular chain of three inverters with identical capacitive loading. 2.2 BENG 221 Lecture 2 Tutorial Today’s Coverage: Overview Example: Ring Oscillator Dynamics Analytic ODE Solution Example: Ring Oscillator Dynamics Numerical Verification Numerical Simulation Analytic ODE Solution Further Reading Numerical Verification Numerical Simulation 2.3 BENG 221 Lecture 2 Tutorial Some circuit elements Overview Example: Ring Oscillator Dynamics Analytic ODE Solution Numerical Verification Numerical Simulation Further Reading Figure : An inverting transconductor (inverter) converts and input voltage to an output current, with gain −G. iout = g(vin ) ≈ −Gvin 2.4 (1) Figure : A capacitor converts charge, or integrated current, to voltage with gain 1/C. Q 1 v= = C C Z t i dt −∞ (2) BENG 221 Lecture 2 Tutorial Ring Oscillator Overview Example: Ring Oscillator Dynamics Analytic ODE Solution Numerical Verification Numerical Simulation Figure : A 3-inverter ring oscillator with capacitive loading. Further Reading dv1 dt dv2 C dt dv3 C dt C 2.5 = g(v3 ) ≈ −G v3 v1 (0) = g(v1 ) ≈ −G v1 (3) = g(v2 ) ≈ −G v2 = v10 v2 (0) = v20 (4) v3 (0) v30 = BENG 221 Lecture 2 Tutorial Eigenvalues Ring oscillator ODE dynamics in matrix notation: dv = Av dt Overview Example: Ring Oscillator Dynamics Analytic ODE Solution Numerical Verification Numerical Simulation Further Reading v(0) = v0 (5) with v1 v = v2 v3 0 A = −1 0 0 −1 0 0 −1 0 v10 v(0) = v20 (6) v30 where G/C ≡ 1 with no loss of generality. Eigenvectors xi and corresponding eigenvalues λi of A satisfy A xi = λi xi , or det(A − λi I) = 0, which reduces to λi 3 + 1 = 0, with three solutions: 1 3 λi = (−1) = 2.6 +jπ/3 e e−jπ/3 −1 √ = 12 + j √23 = 12 − j 23 (7) BENG 221 Lecture 2 Tutorial Overview Eigenvectors The corresponding eigenvectors are: Example: Ring Oscillator Dynamics Analytic ODE Solution λ1 = −1 : x1 Numerical Verification Numerical Simulation λ2 = e+jπ/3 = 1 2 = √ +j 3 2 : x2 = Further Reading λ3 = e−jπ/3 = 1 2 √ −j 3 2 : x3 = 1 √1 1 3 1 1 √1 e +j2π/3 3 −j2π/3 e 1 √1 e −j2π/3 3 e+j2π/3 (8) The eigenvectors form a complex orthonormal basis: xi ∗ xj = δij , i, j = 1, . . . 3 where xi ∗ is the complex conjugate transpose of xi . 2.7 (9) BENG 221 Lecture 2 Tutorial Eigenmodes The general solution is the superposition of eigenmodes (see Lecture 1): Overview Example: Ring Oscillator Dynamics Analytic ODE Solution Numerical Verification Numerical Simulation Further Reading 2.8 v = 3 X ci xi eλi t i=1 1 1 = c1 e−t √ 1 + 3 1 1 √ 3 1 1 c2 e 2 t ej 2 t √ e+j2π/3 + 3 e−j2π/3 1 √ 3 1 1 c3 e 2 t e−j 2 t √ e−j2π/3 3 e+j2π/3 (10) v(t) is real, and so c2 and c3 must be complex conjugate. Therefore, the second and third eigenmodes are oscillatory with an exponentially rising carrier. The first eigenmode is a decaying exponential common-mode transient. BENG 221 Lecture 2 Tutorial First Eigenmode– Common-mode Decaying Exponential IC: (1 1 1) 1.2 v1 v2 v3 Overview Example: Ring Oscillator Dynamics Analytic ODE Solution 1 0.8 Numerical Verification Numerical Simulation 0.6 Further Reading 0.4 0.2 0 0 1 2 3 4 5 t 6 7 8 9 10 Figure : Ring oscillator ODE solution for v(0) = (1, 1, 1)T . 2.9 BENG 221 Lecture 2 Tutorial Overview Example: Ring Oscillator Dynamics Second/third Eigenmode– Exponentially Rising Three-phase Oscillations IC: (1 −0.5 −0.5) 4 5 t 6 150 v1 v2 v3 100 Analytic ODE Solution Numerical Verification 50 Numerical Simulation Further Reading 0 −50 −100 −150 0 1 2 3 7 8 9 10 Figure : Ring oscillator ODE solution for v(0) = (1, − 21 , − 12 )T . 2.10 BENG 221 Lecture 2 Tutorial Overview Example: Ring Oscillator Dynamics Initial Conditions The IC constrained solution is obtained by virtue of the orthonormality of the eigenvectors (see also Lecture 1): Analytic ODE Solution v= x∗i v(0) xi eλi t (11) i=1 Numerical Verification Numerical Simulation n X which, using the identity e+jα + e−jα = 2 cos(α), leads to: Further Reading v1 = e−t (v10 + v20 + v30 ) + (12) 3 √ 2 et/2 3 (v10 cos( t) + 3 2 √ √ 3 2π 3 2π v20 cos( t+ ) + v30 cos( t− )) 2 3 2 3 and identical expressions for v2 and v3 under ordered permutation of the indices (consistent with the ring symmetry). 2.11 BENG 221 Lecture 2 Tutorial Matlab Implementation Overview Example: Ring Oscillator Dynamics Analytic ODE Solution Numerical Verification Numerical Simulation Further Reading Using the eigenvector-eigenvalue decomposition of A in matrix form: AX=Xs (13) where X = (x1 , x2 , x3 ) and s = diag(λ1 , λ2 , λ3 ), the solution (11) can be expressed in matrix form: v = X diag(X∗ v(0))ediag(s)t for efficient matlab implementation: [X, s] = eig(A); V = X * diag(X’ * V0) * exp(diag(s) * t); 2.12 (14) BENG 221 Lecture 2 Tutorial Initial Conditions IC: (1 0 0) 100 v1 v2 v3 Overview Example: Ring Oscillator Dynamics Analytic ODE Solution 80 60 40 Numerical Verification Numerical Simulation Further Reading 20 0 −20 −40 −60 −80 0 1 2 3 4 5 t 6 7 8 9 10 Figure : Ring oscillator ODE solution for v(0) = (1, 0, 0)T . 2.13 BENG 221 Lecture 2 Tutorial Euler Integration Euler numerical integration produces approximate solutions to: Overview dx = f(x(t), t) dt Example: Ring Oscillator Dynamics Analytic ODE Solution Numerical Verification Numerical Simulation Further Reading (15) at discrete time intervals t = n∆t, by finite difference approximation of the derivative: dx 1 (t) = (x(t + ∆t) − x(t)) + O(∆t 2 ) dt ∆t (16) leading to the recursion: x(t + ∆t) ≈ x(t) + ∆t f(x(t), t). Matlab Euler example (ring oscillator): Ve = V0; % Euler approximation, initialize to IC Vs = V0; % Euler state variable, initialize for te = tstep:tstep:trange Vs = Vs + A * Vs * tstep; Ve = [Ve, Vs]; end 2.14 (17) BENG 221 Lecture 2 Tutorial Euler Integration IC: (1 0 0) 150 v1 v2 v3 Overview Example: Ring Oscillator Dynamics 100 Analytic ODE Solution Numerical Verification 50 Numerical Simulation Further Reading 0 −50 −100 0 1 2 3 4 5 t 6 7 8 9 10 Figure : Ring oscillator ODE simulation using Euler integration. 2.15 BENG 221 Lecture 2 Tutorial Overview Example: Ring Oscillator Dynamics Analytic ODE Solution Numerical Verification Numerical Simulation Crank-Nicolson Integration Better numerical ODE methods exist that use higher-order finite difference approximations of the derivative. Crank-Nicolson is a second order method that approximates (15) more accurately using a centered version of the finite difference approximation of the derivative: ∆t 1 dx (t + )= (x(t + ∆t) − x(t)) + O(∆t 3 ) (18) dt 2 ∆t leading to a recursion: Further Reading x(t + ∆t) ≈ x(t) + ∆t f(x(t + ≈ x(t) + ∆t ∆t ), t + ) 2 2 ∆t (f(x(t), t) + f(x(t + ∆t), t + ∆t)).(19) 2 Matlab CN example (ring oscillator): 2.16 G = (eye(3) - A * tstep / 2) \ (eye(3) + A * tstep / 2); Vc = V0; % CN approximation, initialize to IC Vs = V0; % CN state variable, initialize for te = tstep:tstep:trange Vs = G * Vs; Vc = [Vc, Vs]; end BENG 221 Lecture 2 Tutorial Crank-Nicolson Integration IC: (1 0 0) 100 v1 v2 v3 Overview Example: Ring Oscillator Dynamics Analytic ODE Solution 80 60 40 Numerical Verification Numerical Simulation Further Reading 20 0 −20 −40 −60 −80 0 1 2 3 4 5 t 6 7 8 9 Figure : Ring oscillator ODE simulation using Crank-Nicolson integration. 2.17 10 BENG 221 Lecture 2 Tutorial Higher-Order Integration Overview Example: Ring Oscillator Dynamics Analytic ODE Solution Numerical Verification Numerical Simulation Further Reading Crank-Nicolson (19) is implicit in that the solution at time step t + ∆t is recursive in the state variable x(t + ∆t), rather than forward e.g., given in previous values of the state variable x(t). More advanced methods, such as Runge-Kutta and several of Matlab’s built-in ODE solvers, are explicit and/or higher order, allowing faster integration although possibly at the expense of numerical stability. Matlab ode23 example (ring oscillator): OdeOptions = odeset(’RelTol’, 1e-9); % accuracy, please dVdt = @(t,V) A * V; [tm, Vm] = ode23(dVdt, [0 trange], V0); 2.18 BENG 221 Lecture 2 Tutorial Explicit Forward Second-Order Integration IC: (1 0 0) 100 v1 v2 v3 Overview Example: Ring Oscillator Dynamics Analytic ODE Solution 80 60 40 Numerical Verification Numerical Simulation Further Reading 20 0 −20 −40 −60 −80 2.19 0 1 2 3 4 5 t 6 7 8 9 10 Figure : Ring oscillator ODE simulation using an explicit version of Crank-Nicolson integration using a forward series expansion up to second order. BENG 221 Lecture 2 Tutorial Matlab Built-in ode23 Solver IC: (1 0 0) 100 v1 v2 v3 Overview Example: Ring Oscillator Dynamics Analytic ODE Solution 80 60 40 Numerical Verification Numerical Simulation Further Reading 20 0 −20 −40 −60 −80 0 1 2 3 4 5 t 6 7 8 9 10 Figure : Ring oscillator ODE simulation using the Matlab built-in ode23 numeric ODE solver. 2.20 BENG 221 Lecture 2 Tutorial Bibliography Overview Example: Ring Oscillator Dynamics Analytic ODE Solution Numerical Verification Numerical Simulation Further Reading R. Haberman, Applied Partial Differential Equations with Fourier Series and Boundary Value Problems, 4th Ed., 2004, Ch. 6. Wikipedia, Conjugate Transpose, http: //en.wikipedia.org/wiki/Conjugate_transpose. Wikipedia, Numerical Ordinary Differential Equations, http://en.wikipedia.org/wiki/Numerical_ ordinary_differential_equations. Wikipedia, Runge Kutta Methods, http: //en.wikipedia.org/wiki/Runge-Kutta_methods. 2.21
© Copyright 2026 Paperzz