Skip to content
Published on

Engineering Mathematics 1: Ordinary Differential Equations & Laplace Transform - Complete Guide

Authors

Engineering Mathematics 1: Ordinary Differential Equations (ODE)

Engineering mathematics is an unavoidable subject for any engineering student. In particular, Ordinary Differential Equations (ODEs) form the mathematical foundation of virtually every engineering discipline — from circuit analysis and control system design to mechanical vibration analysis. This article systematically explains ODEs from the basics to Laplace transforms, centered on engineering application examples.


1. Fundamentals of Differential Equations

What is a Differential Equation?

A differential equation is an equation that expresses a relationship between an unknown function and its derivatives. For example:

dydx=2x,y+3y+2y=0,ut=k2ux2\frac{dy}{dx} = 2x, \quad y'' + 3y' + 2y = 0, \quad \frac{\partial u}{\partial t} = k\frac{\partial^2 u}{\partial x^2}

Differential equations are a core tool for mathematically modeling natural phenomena and engineering systems.

Classification: ODE vs PDE

Ordinary Differential Equation (ODE): Contains derivatives with respect to only one independent variable.

d2xdt2+2dxdt+x=0\frac{d^2x}{dt^2} + 2\frac{dx}{dt} + x = 0

Partial Differential Equation (PDE): Contains partial derivatives with respect to two or more independent variables.

ut=c22ux2\frac{\partial u}{\partial t} = c^2\frac{\partial^2 u}{\partial x^2}

This article focuses on ODEs.

Order and Degree

The order is the highest derivative appearing in the equation.

  • First-order ODE: y+y=xy' + y = x (highest derivative is yy')
  • Second-order ODE: y+2y+y=0y'' + 2y' + y = 0 (highest derivative is yy'')

The degree is the exponent of the highest-order derivative. In most engineering problems, the degree is 1.

Linear vs Nonlinear

Linear ODE: The unknown function and its derivatives appear only as first-degree terms.

an(x)y(n)+an1(x)y(n1)++a1(x)y+a0(x)y=f(x)a_n(x)y^{(n)} + a_{n-1}(x)y^{(n-1)} + \cdots + a_1(x)y' + a_0(x)y = f(x)

Nonlinear ODE: Contains nonlinear terms such as y2y^2, yyy \cdot y', sin(y)\sin(y), etc.

y+sin(y)=0(pendulum equation)y'' + \sin(y) = 0 \quad \text{(pendulum equation)}

General Solution, Particular Solution, Singular Solution

  • General solution: A complete solution containing arbitrary constants
  • Particular solution: A solution obtained by applying initial conditions to determine the constants
  • Singular solution: A special solution that cannot be obtained from the general solution

ODEs in Engineering

Most engineering systems are described by ODEs.

RC charging circuit: RCdvdt+v=VsRC\frac{dv}{dt} + v = V_s

Spring-mass-damper system: mx¨+cx˙+kx=F(t)m\ddot{x} + c\dot{x} + kx = F(t)

Population growth model: dPdt=kP\frac{dP}{dt} = kP

RL circuit: Ldidt+Ri=E(t)L\frac{di}{dt} + Ri = E(t)

All of these are ODEs. Learning how to solve them allows you to fully analyze the dynamic behavior of engineering systems.


2. First-Order Ordinary Differential Equations

2.1 Separation of Variables

Form: dydx=f(x)g(y)\frac{dy}{dx} = f(x)g(y)

Solution procedure:

dyg(y)=f(x)dx\frac{dy}{g(y)} = f(x)dx

Integrate both sides:

dyg(y)=f(x)dx+C\int \frac{dy}{g(y)} = \int f(x)dx + C

Example: RC Charging Circuit

Circuit equation: dvdt=VsvRC\frac{dv}{dt} = \frac{V_s - v}{RC}

Separation of variables: dvVsv=dtRC\frac{dv}{V_s - v} = \frac{dt}{RC}

Integration: lnVsv=tRC+C1-\ln|V_s - v| = \frac{t}{RC} + C_1

Applying initial condition v(0)=0v(0) = 0:

Vsv=Vset/(RC)V_s - v = V_s e^{-t/(RC)}

v(t)=Vs(1et/(RC))\boxed{v(t) = V_s\left(1 - e^{-t/(RC)}\right)}

This result represents the transient response of an RC circuit. The voltage converges to VsV_s at a rate determined by the time constant τ=RC\tau = RC.

Physical interpretation:

  • At t=τt = \tau: v0.632Vsv \approx 0.632 V_s (63.2% charged)
  • At t=5τt = 5\tau: v0.993Vsv \approx 0.993 V_s (almost fully charged)

2.2 Integrating Factor Method

Standard form of a first-order linear ODE: dydx+P(x)y=Q(x)\frac{dy}{dx} + P(x)y = Q(x)

Integrating factor: μ(x)=eP(x)dx\mu(x) = e^{\int P(x)dx}

Derivation:

Multiply both sides by μ(x)\mu(x): μ(x)dydx+μ(x)P(x)y=μ(x)Q(x)\mu(x)\frac{dy}{dx} + \mu(x)P(x)y = \mu(x)Q(x)

The left side, by the product rule: ddx[μ(x)y]=μ(x)Q(x)\frac{d}{dx}[\mu(x)y] = \mu(x)Q(x)

Integrating: μ(x)y=μ(x)Q(x)dx+C\mu(x)y = \int \mu(x)Q(x)dx + C

y=1μ(x)[μ(x)Q(x)dx+C]\boxed{y = \frac{1}{\mu(x)}\left[\int \mu(x)Q(x)dx + C\right]}

Example: RL Circuit

Ldidt+Ri=EL\frac{di}{dt} + Ri = E

Converting to standard form: didt+RLi=EL\frac{di}{dt} + \frac{R}{L}i = \frac{E}{L}

Integrating factor: μ(t)=e(R/L)t\mu(t) = e^{(R/L)t}

ddt[e(R/L)ti]=ELe(R/L)t\frac{d}{dt}\left[e^{(R/L)t} \cdot i\right] = \frac{E}{L}e^{(R/L)t}

Integrating: e(R/L)ti=ERe(R/L)t+Ce^{(R/L)t} \cdot i = \frac{E}{R}e^{(R/L)t} + C

Applying initial condition i(0)=0i(0) = 0:

i(t)=ER(1e(R/L)t)\boxed{i(t) = \frac{E}{R}\left(1 - e^{-(R/L)t}\right)}

The current converges to steady state E/RE/R with time constant τ=L/R\tau = L/R.

2.3 Exact ODEs

Form: M(x,y)dx+N(x,y)dy=0M(x,y)dx + N(x,y)dy = 0

Exactness condition: My=Nx\frac{\partial M}{\partial y} = \frac{\partial N}{\partial x}

When this condition is satisfied, there exists a potential function FF such that F(x,y)=CF(x,y) = C.

Solution procedure:

  1. Integrate Fx=M\frac{\partial F}{\partial x} = M with respect to xx to find FF
  2. Use the condition Fy=N\frac{\partial F}{\partial y} = N to determine the integration constant
  3. General solution: F(x,y)=CF(x,y) = C

Example:

(2xy+y2)dx+(x2+2xy)dy=0(2xy + y^2)dx + (x^2 + 2xy)dy = 0

Checking exactness: My=2x+2y=Nx\frac{\partial M}{\partial y} = 2x + 2y = \frac{\partial N}{\partial x}

Since it is exact: F=Mdx=(2xy+y2)dx=x2y+xy2+g(y)F = \int M\,dx = \int (2xy + y^2)dx = x^2y + xy^2 + g(y)

Since Fy=x2+2xy+g(y)=N=x2+2xy\frac{\partial F}{\partial y} = x^2 + 2xy + g'(y) = N = x^2 + 2xy, we have g(y)=0g'(y) = 0, g(y)=Cg(y) = C

General solution: x2y+xy2=Cx^2y + xy^2 = C

2.4 Bernoulli Equation

Form: dydx+P(x)y=Q(x)yn(n0,1)\frac{dy}{dx} + P(x)y = Q(x)y^n \quad (n \neq 0, 1)

Substitution: Setting v=y1nv = y^{1-n} transforms this into a linear ODE.

Since v=(1n)ynyv' = (1-n)y^{-n}y', dividing the original equation by yny^n:

yndydx+P(x)y1n=Q(x)y^{-n}\frac{dy}{dx} + P(x)y^{1-n} = Q(x)

11ndvdx+P(x)v=Q(x)\frac{1}{1-n}\frac{dv}{dx} + P(x)v = Q(x)

dvdx+(1n)P(x)v=(1n)Q(x)\frac{dv}{dx} + (1-n)P(x)v = (1-n)Q(x)

This is a first-order linear ODE in vv, solvable by the integrating factor method.

Application: The logistic growth model dPdt=rP(1PK)\frac{dP}{dt} = rP\left(1 - \frac{P}{K}\right) is a Bernoulli equation with n=2n=2.


3. Second-Order Linear Ordinary Differential Equations

3.1 Homogeneous Equations

Standard form: ay+by+cy=0ay'' + by' + cy = 0

Characteristic equation derivation: Substitute y=erxy = e^{rx}.

ar2erx+brerx+cerx=0a r^2 e^{rx} + b r e^{rx} + c e^{rx} = 0

ar2+br+c=0\boxed{ar^2 + br + c = 0}

Three cases arise depending on the sign of the discriminant Δ=b24ac\Delta = b^2 - 4ac.

Case 1: Two distinct real roots (Δ>0\Delta > 0)

For r1r2r_1 \neq r_2: y=C1er1x+C2er2xy = C_1 e^{r_1 x} + C_2 e^{r_2 x}

Case 2: Repeated real root (Δ=0\Delta = 0)

For r1=r2=r=b/(2a)r_1 = r_2 = r = -b/(2a): y=(C1+C2x)erxy = (C_1 + C_2 x)e^{rx}

The term C2xerxC_2 x e^{rx} must be added so that the Wronskian is nonzero, constructing an independent second solution.

Case 3: Complex conjugate roots (Δ<0\Delta < 0)

For r=α±iβr = \alpha \pm i\beta (where α=b/(2a)\alpha = -b/(2a), β=4acb2/(2a)\beta = \sqrt{4ac - b^2}/(2a)): y=eαx(C1cosβx+C2sinβx)y = e^{\alpha x}(C_1\cos\beta x + C_2\sin\beta x)

This form is converted to real solutions using Euler's formula eiβx=cosβx+isinβxe^{i\beta x} = \cos\beta x + i\sin\beta x.

3.2 Complete Analysis of RLC Circuits

Circuit equation (in terms of charge q(t)q(t)): Ld2qdt2+Rdqdt+qC=0L\frac{d^2q}{dt^2} + R\frac{dq}{dt} + \frac{q}{C} = 0

In standard form: q+RLq+1LCq=0q'' + \frac{R}{L}q' + \frac{1}{LC}q = 0

Characteristic equation: r2+RLr+1LC=0r^2 + \frac{R}{L}r + \frac{1}{LC} = 0

r=R2L±(R2L)21LCr = -\frac{R}{2L} \pm \sqrt{\left(\frac{R}{2L}\right)^2 - \frac{1}{LC}}

Defining the damping coefficient α=R/(2L)\alpha = R/(2L) and resonant frequency ω0=1/LC\omega_0 = 1/\sqrt{LC}:

r=α±α2ω02r = -\alpha \pm \sqrt{\alpha^2 - \omega_0^2}

Overdamped: α>ω0\alpha > \omega_0 (R>2L/CR > 2\sqrt{L/C})

q(t)=C1er1t+C2er2t(r1,r2<0)q(t) = C_1 e^{r_1 t} + C_2 e^{r_2 t} \quad (r_1, r_2 < 0)

A sum of two exponential terms — decays monotonically without oscillation.

Critically Damped: α=ω0\alpha = \omega_0 (R=2L/CR = 2\sqrt{L/C})

q(t)=(C1+C2t)eαtq(t) = (C_1 + C_2 t)e^{-\alpha t}

Returns to equilibrium most rapidly without oscillation. Very important in control system design.

Underdamped: α<ω0\alpha < \omega_0 (R<2L/CR < 2\sqrt{L/C})

Defining the damped oscillation frequency ωd=ω02α2\omega_d = \sqrt{\omega_0^2 - \alpha^2}:

q(t)=eαt(C1cosωdt+C2sinωdt)q(t) = e^{-\alpha t}(C_1\cos\omega_d t + C_2\sin\omega_d t)

Oscillates while decaying. Commonly seen in communication circuits and vibration systems.

Summary of physical interpretation:

ConditionNameResponse Characteristics
R>2L/CR > 2\sqrt{L/C}OverdampedSlow decay without oscillation
R=2L/CR = 2\sqrt{L/C}Critically dampedFastest decay without oscillation
R<2L/CR < 2\sqrt{L/C}UnderdampedOscillates and decays
R=0R = 0UndampedContinuous oscillation

3.3 Non-homogeneous Equations

Form: ay+by+cy=f(x)ay'' + by' + cy = f(x)

Complete solution: y=yh+ypy = y_h + y_p

  • yhy_h: General solution of the homogeneous equation (complementary function)
  • ypy_p: Particular solution

Method of Undetermined Coefficients

Guess the form of ypy_p based on the form of f(x)f(x).

Form of f(x)f(x)Guessed form of ypy_p
keaxke^{ax}AeaxAe^{ax}
kxnkx^nAnxn++A1x+A0A_n x^n + \cdots + A_1 x + A_0
kcosωxk\cos\omega x or ksinωxk\sin\omega xAcosωx+BsinωxA\cos\omega x + B\sin\omega x
keaxcosωxke^{ax}\cos\omega xeax(Acosωx+Bsinωx)e^{ax}(A\cos\omega x + B\sin\omega x)

Note: If the guessed form of ypy_p overlaps with a term in yhy_h, multiply by xx.

Example: y+4y=3cos2xy'' + 4y = 3\cos 2x

Homogeneous solution: yh=C1cos2x+C2sin2xy_h = C_1\cos 2x + C_2\sin 2x

Since the guessed form of ypy_p overlaps with yhy_h, modify: yp=x(Acos2x+Bsin2x)y_p = x(A\cos 2x + B\sin 2x)

After substitution: A=0A = 0, B=3/4B = 3/4

yp=34xsin2xy_p = \frac{3}{4}x\sin 2x

This is resonance, where the amplitude increases proportionally with time.

Forced vibration response:

mx¨+cx˙+kx=F0cosωtm\ddot{x} + c\dot{x} + kx = F_0\cos\omega t

Steady-state particular solution: xp(t)=F0/k(1r2)2+(2ζr)2cos(ωtϕ)x_p(t) = \frac{F_0/k}{\sqrt{(1-r^2)^2 + (2\zeta r)^2}}\cos(\omega t - \phi)

Where frequency ratio r=ω/ωnr = \omega/\omega_n and damping ratio ζ=c/(2mk)\zeta = c/(2\sqrt{mk}).

The amplitude is maximum at r=1r = 1 (resonance condition).

Variation of Parameters

Used for general f(x)f(x) where the method of undetermined coefficients cannot be applied.

Given yh=C1y1+C2y2y_h = C_1 y_1 + C_2 y_2:

yp=y1y2fWdx+y2y1fWdxy_p = -y_1 \int \frac{y_2 f}{W}dx + y_2 \int \frac{y_1 f}{W}dx

Wronskian: W=y1y2y1y2W = y_1 y_2' - y_1' y_2

This formula applies to any continuous function f(x)f(x).


4. Systems of Differential Equations

4.1 Matrix Representation

A system of nn first-order ODEs:

dXdt=AX\frac{d\mathbf{X}}{dt} = A\mathbf{X}

Where X=[x1,x2,,xn]T\mathbf{X} = [x_1, x_2, \ldots, x_n]^T and AA is an n×nn \times n coefficient matrix.

4.2 Eigenvalue/Eigenvector Solution

Form of solution: X=veλt\mathbf{X} = \mathbf{v}e^{\lambda t}

Substituting: λv=Av\lambda \mathbf{v} = A\mathbf{v}

So λ\lambda is an eigenvalue of AA, and v\mathbf{v} is the corresponding eigenvector.

Characteristic equation: det(AλI)=0\det(A - \lambda I) = 0

Example: Two connected tanks system

ddt(x1x2)=(2112)(x1x2)\frac{d}{dt}\begin{pmatrix} x_1 \\ x_2 \end{pmatrix} = \begin{pmatrix} -2 & 1 \\ 1 & -2 \end{pmatrix}\begin{pmatrix} x_1 \\ x_2 \end{pmatrix}

Characteristic equation: (λ+2)21=0(\lambda+2)^2 - 1 = 0

λ1=1,λ2=3\lambda_1 = -1, \quad \lambda_2 = -3

Eigenvectors: v1=[1,1]T\mathbf{v}_1 = [1, 1]^T, v2=[1,1]T\mathbf{v}_2 = [1, -1]^T

General solution: X=C1(11)et+C2(11)e3t\mathbf{X} = C_1 \begin{pmatrix} 1 \\ 1 \end{pmatrix} e^{-t} + C_2 \begin{pmatrix} 1 \\ -1 \end{pmatrix} e^{-3t}

4.3 Application to Circuit Network Analysis

Circuit with two loops (Kirchhoff's voltage law):

L1di1dt+R1i1Mdi2dt=E1(t)L_1\frac{di_1}{dt} + R_1 i_1 - M\frac{di_2}{dt} = E_1(t) L2di2dt+R2i2Mdi1dt=E2(t)L_2\frac{di_2}{dt} + R_2 i_2 - M\frac{di_1}{dt} = E_2(t)

Where MM is the mutual inductance. This can be written in matrix form and solved using the eigenvalue method or Laplace transform.


5. Laplace Transform

5.1 Definition and Convergence

Definition: L{f(t)}=F(s)=0f(t)estdt\mathcal{L}\{f(t)\} = F(s) = \int_0^\infty f(t)e^{-st}dt

s=σ+jωs = \sigma + j\omega is a complex variable. For convergence, Re(s)>σc\text{Re}(s) > \sigma_c (half-plane of convergence) must be satisfied.

Why use the Laplace transform?

  • Differential operations are converted to algebraic operations
  • Initial conditions are automatically incorporated
  • Complex ODEs can be solved as simple algebraic equations
  • It forms the basis of the transfer function concept

5.2 Key Transform Pairs

f(t)f(t)F(s)=L{f(t)}F(s) = \mathcal{L}\{f(t)\}
11 (unit step)1s\dfrac{1}{s}
tt1s2\dfrac{1}{s^2}
tnt^nn!sn+1\dfrac{n!}{s^{n+1}}
eate^{at}1sa\dfrac{1}{s-a}
sinωt\sin\omega tωs2+ω2\dfrac{\omega}{s^2+\omega^2}
cosωt\cos\omega tss2+ω2\dfrac{s}{s^2+\omega^2}
eatsinωte^{at}\sin\omega tω(sa)2+ω2\dfrac{\omega}{(s-a)^2+\omega^2}
eatcosωte^{at}\cos\omega tsa(sa)2+ω2\dfrac{s-a}{(s-a)^2+\omega^2}
δ(t)\delta(t) (impulse)11
u(ta)u(t-a) (delayed step)eass\dfrac{e^{-as}}{s}

Derivation example: L{eat}\mathcal{L}\{e^{at}\}

L{eat}=0eatestdt=0e(sa)tdt=[e(sa)t(sa)]0=1sa\mathcal{L}\{e^{at}\} = \int_0^\infty e^{at} e^{-st} dt = \int_0^\infty e^{-(s-a)t} dt = \left[\frac{e^{-(s-a)t}}{-(s-a)}\right]_0^\infty = \frac{1}{s-a}

Converges when s>as > a.

5.3 Key Properties

Linearity: L{af(t)+bg(t)}=aF(s)+bG(s)\mathcal{L}\{af(t) + bg(t)\} = aF(s) + bG(s)

Time shift (First shifting theorem): L{eatf(t)}=F(sa)\mathcal{L}\{e^{at}f(t)\} = F(s-a)

Frequency shift (Second shifting theorem): L{f(ta)u(ta)}=easF(s)\mathcal{L}\{f(t-a)u(t-a)\} = e^{-as}F(s)

Differentiation transform (most important property): L{f(t)}=sF(s)f(0)\mathcal{L}\{f'(t)\} = sF(s) - f(0) L{f(t)}=s2F(s)sf(0)f(0)\mathcal{L}\{f''(t)\} = s^2F(s) - sf(0) - f'(0) L{f(n)(t)}=snF(s)sn1f(0)sn2f(0)f(n1)(0)\mathcal{L}\{f^{(n)}(t)\} = s^nF(s) - s^{n-1}f(0) - s^{n-2}f'(0) - \cdots - f^{(n-1)}(0)

Initial conditions are automatically included in the s-domain.

Integration transform: L{0tf(τ)dτ}=F(s)s\mathcal{L}\left\{\int_0^t f(\tau)d\tau\right\} = \frac{F(s)}{s}

Convolution theorem: L{(fg)(t)}=F(s)G(s)\mathcal{L}\{(f*g)(t)\} = F(s)G(s)

Where (fg)(t)=0tf(τ)g(tτ)dτ(f*g)(t) = \int_0^t f(\tau)g(t-\tau)d\tau

This theorem mathematically proves that the output of a system is the convolution of the impulse response and the input signal.

Final value theorem: limtf(t)=lims0sF(s)\lim_{t\to\infty} f(t) = \lim_{s\to 0} sF(s)

Allows determination of the steady-state value without solving in the t-domain.

Initial value theorem: limt0+f(t)=limssF(s)\lim_{t\to 0^+} f(t) = \lim_{s\to\infty} sF(s)

5.4 Inverse Laplace Transform

Partial Fraction Decomposition:

For F(s)=P(s)/Q(s)F(s) = P(s)/Q(s), factor the denominator and decompose into a sum of table transform pairs.

Case 1: Distinct real poles

F(s)=N(s)(sp1)(sp2)(spn)=A1sp1+A2sp2+F(s) = \frac{N(s)}{(s-p_1)(s-p_2)\cdots(s-p_n)} = \frac{A_1}{s-p_1} + \frac{A_2}{s-p_2} + \cdots

Ak=limspk(spk)F(s)A_k = \lim_{s\to p_k}(s-p_k)F(s)

Case 2: Repeated poles (s=ps = p is an mm-fold root)

F(s)=+Am(sp)m+Am1(sp)m1++A1spF(s) = \cdots + \frac{A_m}{(s-p)^m} + \frac{A_{m-1}}{(s-p)^{m-1}} + \cdots + \frac{A_1}{s-p}

Ak=1(mk)![dmkdsmk(sp)mF(s)]s=pA_k = \frac{1}{(m-k)!}\left[\frac{d^{m-k}}{ds^{m-k}}(s-p)^m F(s)\right]_{s=p}

Case 3: Complex conjugate poles

As+Bs2+2αs+(α2+β2)eαt(C1cosβt+C2sinβt)\frac{As + B}{s^2 + 2\alpha s + (\alpha^2 + \beta^2)} \Rightarrow e^{-\alpha t}(C_1\cos\beta t + C_2\sin\beta t)

Heaviside Expansion Theorem:

When the denominator is a product of distinct linear factors: F(s)=k=1nN(pk)Q(pk)1spkF(s) = \sum_{k=1}^n \frac{N(p_k)}{Q'(p_k)} \cdot \frac{1}{s - p_k}

5.5 Solving ODEs with the Laplace Transform

Example: RLC Series Circuit Transient Response

Ld2idt2+Rdidt+iC=E0δ(t)L\frac{d^2i}{dt^2} + R\frac{di}{dt} + \frac{i}{C} = E_0\delta(t)

Initial conditions: i(0)=0i(0) = 0, i(0)=0i'(0) = 0 (no charge on capacitor)

Solution:

Applying the Laplace transform to both sides:

I(s)=E0/Ls2+(R/L)s+1/(LC)I(s) = \frac{E_0/L}{s^2 + (R/L)s + 1/(LC)}

Defining α=R/(2L)\alpha = R/(2L), ω0=1/LC\omega_0 = 1/\sqrt{LC}, ωd=ω02α2\omega_d = \sqrt{\omega_0^2 - \alpha^2} (underdamped case):

I(s)=E0/L(s+α)2+ωd2I(s) = \frac{E_0/L}{(s+\alpha)^2 + \omega_d^2}

Inverse Laplace transform (from table: L{eαtsinωdt}=ωd/[(s+α)2+ωd2]\mathcal{L}\{e^{-\alpha t}\sin\omega_d t\} = \omega_d/[(s+\alpha)^2+\omega_d^2]):

i(t)=E0Lωdeαtsinωdti(t) = \frac{E_0}{L\omega_d}e^{-\alpha t}\sin\omega_d t

This is the impulse response of the RLC circuit, which is also its Green's function.


6. Numerical ODE Solutions with Python

6.1 Using scipy.integrate.solve_ivp

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

# RLC circuit simulation (2nd order ODE -> system of 1st order ODEs)
# L * q'' + R * q' + q/C = Vs (step input)
# State variables: y[0] = q (charge), y[1] = i = dq/dt (current)

def rlc_circuit(t, y, R, L, C, Vs):
    q, dq_dt = y
    # q'' = (Vs - R*i - q/C) / L
    d2q_dt2 = (Vs - R * dq_dt - q / C) / L
    return [dq_dt, d2q_dt2]

# Circuit parameters
R = 100      # Resistance (Ohm)
L = 0.1      # Inductance (H)
C = 1e-6     # Capacitance (F)
Vs = 10.0    # Supply voltage (V)

# Calculate resonant frequency and damping ratio
omega_0 = 1.0 / np.sqrt(L * C)
alpha = R / (2 * L)
zeta = alpha / omega_0
print(f"Resonant frequency: {omega_0/(2*np.pi):.1f} Hz")
print(f"Damping ratio zeta: {zeta:.3f}")
if zeta > 1:
    print("-> Overdamped")
elif zeta == 1:
    print("-> Critically damped")
else:
    print("-> Underdamped")

# Numerical solution
y0 = [0.0, 0.0]  # Initial conditions: q(0) = 0, i(0) = 0
t_span = (0, 0.01)
t_eval = np.linspace(0, 0.01, 2000)

sol = solve_ivp(
    rlc_circuit, t_span, y0,
    t_eval=t_eval,
    args=(R, L, C, Vs),
    method='RK45',
    rtol=1e-8,
    atol=1e-10
)

# Voltage calculation: v_C = q/C
v_C = sol.y[0] / C
i = sol.y[1]

# Visualization
fig, axes = plt.subplots(2, 1, figsize=(10, 8))

axes[0].plot(sol.t * 1e3, v_C, 'b-', linewidth=2, label='Capacitor voltage')
axes[0].axhline(y=Vs, color='r', linestyle='--', label=f'Steady state {Vs}V')
axes[0].set_xlabel('Time (ms)')
axes[0].set_ylabel('Voltage (V)')
axes[0].set_title('RLC Series Circuit - Step Response')
axes[0].legend()
axes[0].grid(True, alpha=0.3)

axes[1].plot(sol.t * 1e3, i * 1e3, 'g-', linewidth=2, label='Current')
axes[1].set_xlabel('Time (ms)')
axes[1].set_ylabel('Current (mA)')
axes[1].set_title('RLC Circuit Current')
axes[1].legend()
axes[1].grid(True, alpha=0.3)

plt.tight_layout()
plt.savefig('rlc_response.png', dpi=150)
plt.show()

6.2 Analytical Solutions with SymPy

import sympy as sp

# Symbol definitions
t, s = sp.symbols('t s')
R_sym, L_sym, C_sym = sp.symbols('R L C', positive=True)
Vs_sym = sp.Symbol('Vs')

# RC circuit analytical solution (solving ODE with sympy)
v = sp.Function('v')
tau = sp.Symbol('tau', positive=True)

# dv/dt = (Vs - v) / (R*C)
ode = sp.Eq(v(t).diff(t), (Vs_sym - v(t)) / (R_sym * C_sym))

# Initial condition v(0) = 0
solution = sp.dsolve(ode, v(t), ics={v(0): 0})
print("RC circuit solution:")
print(solution)
sp.pprint(solution)

# Laplace transform calculation
f = sp.exp(-t) * sp.sin(2*t)
F = sp.laplace_transform(f, t, s, noconds=True)
print(f"\nL{{e^(-t) sin(2t)}} = {F}")

# Inverse Laplace transform
F_inv = sp.inverse_laplace_transform(
    1 / (s**2 + 2*s + 5), s, t
)
print(f"L^(-1){{1/(s^2+2s+5)}} = {F_inv}")

6.3 Comparing Different Integrators

import numpy as np
import matplotlib.pyplot as plt

# Euler method vs RK4 comparison
# Example: y' = -y, y(0) = 1, exact solution y = e^(-t)

def f(t, y):
    return -y

def euler_method(f, t0, y0, h, n):
    t = np.zeros(n+1)
    y = np.zeros(n+1)
    t[0], y[0] = t0, y0
    for i in range(n):
        y[i+1] = y[i] + h * f(t[i], y[i])
        t[i+1] = t[i] + h
    return t, y

def rk4_method(f, t0, y0, h, n):
    t = np.zeros(n+1)
    y = np.zeros(n+1)
    t[0], y[0] = t0, y0
    for i in range(n):
        k1 = h * f(t[i], y[i])
        k2 = h * f(t[i] + h/2, y[i] + k1/2)
        k3 = h * f(t[i] + h/2, y[i] + k2/2)
        k4 = h * f(t[i] + h, y[i] + k3)
        y[i+1] = y[i] + (k1 + 2*k2 + 2*k3 + k4) / 6
        t[i+1] = t[i] + h
    return t, y

h = 0.5
n = 10
t0, y0 = 0.0, 1.0

t_euler, y_euler = euler_method(f, t0, y0, h, n)
t_rk4, y_rk4 = rk4_method(f, t0, y0, h, n)
t_exact = np.linspace(0, n*h, 200)
y_exact = np.exp(-t_exact)

plt.figure(figsize=(10, 5))
plt.plot(t_exact, y_exact, 'k-', linewidth=2, label='Exact solution')
plt.plot(t_euler, y_euler, 'r--o', label=f'Euler method (h={h})')
plt.plot(t_rk4, y_rk4, 'b--s', label=f'RK4 (h={h})')
plt.xlabel('t')
plt.ylabel("y(t)")
plt.title("Euler vs RK4 Comparison: y' = -y")
plt.legend()
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()

# Error comparison
print(f"Euler method error at t=5: {abs(y_euler[-1] - np.exp(-5)):.6f}")
print(f"RK4 error at t=5: {abs(y_rk4[-1] - np.exp(-5)):.6f}")

6.4 Automating Laplace Transforms with Python

import sympy as sp

s, t = sp.symbols('s t', real=True)
a, omega = sp.symbols('a omega', positive=True)

# Auto-generate Laplace transform table
functions = {
    '1': sp.Integer(1),
    't': t,
    't^2': t**2,
    't^n': t**3,
    'e^(at)': sp.exp(a*t),
    'sin(wt)': sp.sin(omega*t),
    'cos(wt)': sp.cos(omega*t),
    't*e^(at)': t * sp.exp(a*t),
    'e^(at)*sin(wt)': sp.exp(a*t) * sp.sin(omega*t),
}

print("Laplace Transform Table:")
print("-" * 50)
for name, func in functions.items():
    F = sp.laplace_transform(func, t, s, noconds=True)
    print(f"L{{{name}}} = {sp.simplify(F)}")

7. Comprehensive Engineering Application Examples

7.1 Transient Analysis of RLC Circuit with Power Source

Problem: A series RLC circuit with R=50ΩR = 50\,\Omega, L=0.2HL = 0.2\,\text{H}, C=100μFC = 100\,\mu\text{F} is connected to a Vs=100VV_s = 100\,\text{V} DC source at t=0t=0. Initial conditions are vC(0)=0v_C(0) = 0, i(0)=0i(0) = 0.

Solving with the Laplace Transform:

Kirchhoff's voltage law: Ldidt+Ri+1Cidt=Vsu(t)L\frac{di}{dt} + Ri + \frac{1}{C}\int i\,dt = V_s u(t)

Substituting i=CdvC/dti = C dv_C/dt and writing in terms of charge qq: Lq¨+Rq˙+qC=VsL\ddot{q} + R\dot{q} + \frac{q}{C} = V_s

Laplace transform: (Ls2+Rs+1C)Q(s)=Vss\left(Ls^2 + Rs + \frac{1}{C}\right)Q(s) = \frac{V_s}{s}

Q(s)=Vss(Ls2+Rs+1C)=Vs/Ls(s2+RLs+1LC)Q(s) = \frac{V_s}{s\left(Ls^2 + Rs + \frac{1}{C}\right)} = \frac{V_s/L}{s\left(s^2 + \frac{R}{L}s + \frac{1}{LC}\right)}

Substituting values: α=R/(2L)=125s1\alpha = R/(2L) = 125\,\text{s}^{-1}, ω0=1/LC223.6s1\omega_0 = 1/\sqrt{LC} \approx 223.6\,\text{s}^{-1}

Since ω0>α\omega_0 > \alpha, this is underdamped.

ωd=ω02α2185.0s1\omega_d = \sqrt{\omega_0^2 - \alpha^2} \approx 185.0\,\text{s}^{-1}

After partial fraction decomposition and inverse Laplace transform:

vC(t)=Vs[1eαt(cosωdt+αωdsinωdt)]v_C(t) = V_s\left[1 - e^{-\alpha t}\left(\cos\omega_d t + \frac{\alpha}{\omega_d}\sin\omega_d t\right)\right]

=100[1e125t(cos185t+0.676sin185t)]V= 100\left[1 - e^{-125t}\left(\cos 185t + 0.676\sin 185t\right)\right]\,\text{V}

7.2 Resonance Analysis of Spring-Mass-Damper System

Problem: m=1kgm = 1\,\text{kg}, k=100N/mk = 100\,\mathrm{N/m}, c=4Ns/mc = 4\,\mathrm{N \cdot s/m}, F(t)=10cosωtNF(t) = 10\cos\omega t\,\mathrm{N}

Natural frequency: ωn=k/m=10rad/s\omega_n = \sqrt{k/m} = 10\,\text{rad/s}

Damping ratio: ζ=c/(2mk)=0.2\zeta = c/(2\sqrt{mk}) = 0.2 (underdamped)

Steady-state response amplitude: X=F0/k(1r2)2+(2ζr)2X = \frac{F_0/k}{\sqrt{(1-r^2)^2 + (2\zeta r)^2}}

At r=ω/ωn=1r = \omega/\omega_n = 1 (resonance): Xresonance=F0/k2ζ=10/1002×0.2=0.25mX_{resonance} = \frac{F_0/k}{2\zeta} = \frac{10/100}{2 \times 0.2} = 0.25\,\text{m}

This is 2.5 times the static deflection F0/k=0.1mF_0/k = 0.1\,\text{m} without resonance. This is the danger of resonance.


Summary and Next Steps

Topics covered in this article:

  1. Differential equation basics: Classification, order, linearity, types of solutions
  2. First-order ODE methods: Separation of variables, integrating factor, exact ODE, Bernoulli equation
  3. Second-order linear ODE: Characteristic equation, three cases, complete RLC circuit analysis
  4. Non-homogeneous equations: Undetermined coefficients, variation of parameters, forced vibration
  5. Systems of ODEs: Matrix representation, eigenvalue/eigenvector solution
  6. Laplace transform: Definition, transform pairs, properties, inverse transform, ODE solving
  7. Python implementation: Numerical and symbolic solutions with scipy and sympy

The next article will cover Fourier series/transform and partial differential equations (PDEs) — the core mathematical tools for signal processing and electromagnetics.


References


Quiz

Q1. What is the integrating factor method used for, and what is the integrating factor for dy/dx + P(x)y = Q(x)?

Answer: The integrating factor method is used to solve first-order linear ODEs of the standard form dy/dx + P(x)y = Q(x). The integrating factor is mu(x) = exp(integral of P(x) dx).

Explanation: Multiplying both sides by mu(x) transforms the left side into the derivative of mu(x)*y, allowing direct integration. This is a systematic technique applicable to any first-order linear ODE.

Q2. In the RLC series circuit, what are the three damping cases and their conditions?

Answer: The three cases depend on the damping coefficient alpha = R/(2L) and resonant frequency omega_0 = 1/sqrt(LC):

  • Overdamped: alpha greater than omega_0, i.e., R greater than 2*sqrt(L/C) — slow decay without oscillation
  • Critically damped: alpha equals omega_0, i.e., R equals 2*sqrt(L/C) — fastest decay without oscillation
  • Underdamped: alpha less than omega_0, i.e., R less than 2*sqrt(L/C) — oscillates and decays

Explanation: The characteristic equation r^2 + (R/L)r + 1/(LC) = 0 has roots r = -alpha plus/minus sqrt(alpha^2 - omega_0^2). The sign of the discriminant determines whether roots are real or complex.

Q3. What is the convolution theorem in the Laplace transform and why is it important?

Answer: The convolution theorem states that the Laplace transform of the convolution of two functions equals the product of their individual Laplace transforms: L{(f*g)(t)} = F(s)*G(s).

Explanation: This theorem is fundamental to engineering because it proves that the output of a linear time-invariant system equals the convolution of the input signal with the system's impulse response. In the s-domain, this becomes simple multiplication, making system analysis much easier.

Q4. What is resonance in a forced vibration system and what conditions cause it?

Answer: Resonance occurs when the frequency ratio r = omega/omega_n equals 1, meaning the driving frequency equals the natural frequency of the system. Under resonance conditions, the steady-state amplitude is X = (F_0/k) / (2*zeta), which can be many times larger than the static deflection.

Explanation: In the method of undetermined coefficients for y'' + 4y = 3*cos(2x), the forcing frequency matches the natural frequency, causing the particular solution to include a factor of x (secular growth). In real systems with damping, amplitude does not grow to infinity but reaches a finite maximum at resonance. Avoiding resonance is critical in structural and mechanical engineering.

Q5. How are eigenvalues and eigenvectors used to solve systems of first-order ODEs?

Answer: For a system dX/dt = AX, we assume solutions of the form X = vexp(lambdat). Substituting gives lambdav = Av, so lambda are eigenvalues and v are eigenvectors of matrix A. The general solution is a linear combination of all eigenvalue-eigenvector pairs: X = sum of Ck * vk * exp(lambda_k * t).

Explanation: Eigenvalues determine the stability and time constants of each mode. If all eigenvalues have negative real parts, the system is stable. The eigenvectors define the directions of each natural mode of the system.