Level 3 — ProductionOrdinary Differential Equations

Ordinary Differential Equations

45 minutes60 marksprintable — key stays hidden on paper

Level: 3 (Production — from-scratch derivations, code-from-memory, explain-out-loud) Time limit: 45 minutes Total marks: 60

Instructions: Derive from first principles where asked. Show all reasoning. Pseudocode/Python must be written from memory. Use ...... / ...... for mathematics.


Question 1. (10 marks) — Integrating factor, derived from scratch.

Consider the general first-order linear ODE dydx+P(x)y=Q(x).\frac{dy}{dx} + P(x)\,y = Q(x).

(a) Derive the integrating factor μ(x)\mu(x) from scratch, showing exactly what condition μ\mu must satisfy for the left-hand side to become an exact derivative. (5)

(b) Hence solve the initial value problem dydx+2xy=cosxx2,y(π)=0,x>0.\frac{dy}{dx} + \frac{2}{x}\,y = \frac{\cos x}{x^2}, \qquad y(\pi)=0, \quad x>0. (5)


Question 2. (12 marks) — Constant-coefficient theory, all three cases.

For the homogeneous equation ay+by+cy=0a y'' + b y' + c y = 0:

(a) Explain out loud (in words + algebra) why substituting y=erxy=e^{rx} produces the characteristic equation, and why a repeated root rr forces a second solution of the form xerxx e^{rx}. Give the reduction-of-order derivation of that second solution. (6)

(b) Solve y4y+13y=0y'' - 4y' + 13y = 0 and write the real general solution, showing the Euler's-formula step that removes the complex exponentials. (6)


Question 3. (10 marks) — Laplace transform from the definition.

(a) Starting from the definition L{f}(s)=0estf(t)dt\mathcal{L}\{f\}(s)=\int_0^\infty e^{-st}f(t)\,dt, prove that L{eat}=1sa,s>a,\mathcal{L}\{e^{at}\}=\frac{1}{s-a}, \quad s>a, and state the region of convergence. (3)

(b) Prove the derivative property L{f(t)}=sF(s)f(0)\mathcal{L}\{f'(t)\} = sF(s) - f(0) from the definition (integration by parts). (4)

(c) Use the two results above to solve y3y=0,  y(0)=2y' - 3y = 0,\; y(0)=2 via Laplace transform. (3)


Question 4. (12 marks) — Laplace with discontinuous forcing.

Solve, using Laplace transforms: y+y=uπ(t),y(0)=0,  y(0)=0,y'' + y = u_\pi(t), \qquad y(0)=0,\; y'(0)=0, where uπ(t)u_\pi(t) is the Heaviside step turning on at t=πt=\pi.

(a) Transform the equation and solve for Y(s)Y(s). (4) (b) Invert using the second shift theorem; write y(t)y(t) as a piecewise function. (6) (c) State the value of yy for t>πt>\pi in simplified trigonometric form. (2)


Question 5. (10 marks) — Systems, phase plane, stability.

Given the linear system x=Ax\mathbf{x}' = A\mathbf{x} with A=(1221).A = \begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix}.

(a) Find eigenvalues and eigenvectors and write the general solution. (5) (b) Classify the critical point at the origin (node/saddle/spiral/centre) and state its stability, justifying from the eigenvalue signs. (3) (c) Explain out loud, for a general 2×22\times2 system, how the trace and determinant of AA determine the equilibrium type. (2)


Question 6. (6 marks) — Euler's method, code from memory.

(a) Write, from memory, a Python function euler(f, x0, y0, h, n) that returns lists of xx and yy values approximating y=f(x,y)y' = f(x,y). (4) (b) For y=yy'=y, y(0)=1y(0)=1, h=0.5h=0.5, compute by hand the Euler estimate of y(1)y(1) (two steps) and compare with the exact value ee. (2)


Answer keyMark scheme & solutions

Question 1

(a) Multiply the ODE by an unknown μ(x)\mu(x): μy+μPy=μQ.\mu y' + \mu P y = \mu Q. We want the LHS to equal ddx(μy)=μy+μy\frac{d}{dx}(\mu y) = \mu y' + \mu' y. (1) Matching the yy terms requires μ=μP.(1 — the key condition)\mu' = \mu P. \quad\text{(1 — the key condition)} This is separable: dμμ=Pdxlnμ=Pdx\frac{d\mu}{\mu} = P\,dx \Rightarrow \ln\mu = \int P\,dx, (1) μ(x)=eP(x)dx.(1)\boxed{\mu(x) = e^{\int P(x)\,dx}}. \quad (1) Then (μy)=μQy=1μμQdx(\mu y)' = \mu Q \Rightarrow y = \frac{1}{\mu}\int \mu Q\,dx. (1)

(b) Here P=2/xP=2/x, so Pdx=2lnx\int P\,dx = 2\ln x, μ=x2\mu = x^2. (1) (x2y)=x2cosxx2=cosx.(1)(x^2 y)' = x^2\cdot\frac{\cos x}{x^2} = \cos x. \quad (1) Integrate: x2y=sinx+Cx^2 y = \sin x + C. (1) Apply y(π)=0y(\pi)=0: π20=sinπ+C=0+CC=0\pi^2\cdot 0 = \sin\pi + C = 0 + C \Rightarrow C=0. (1) y=sinxx2.(1)\boxed{y = \frac{\sin x}{x^2}}. \quad (1)


Question 2

(a) For ay+by+cy=0ay''+by'+cy=0 with constant coefficients, derivatives of erxe^{rx} reproduce erxe^{rx} times a constant, so the equation collapses to an algebraic one: ar2erx+brerx+cerx=erx(ar2+br+c)=0.a r^2 e^{rx} + b r e^{rx} + c e^{rx} = e^{rx}(ar^2+br+c)=0. Since erx0e^{rx}\ne0, we need ar2+br+c=0ar^2+br+c=0 — the characteristic equation. (2)

Repeated root case: if rr is a double root, r=b/(2a)r=-b/(2a) and we only get one solution y1=erxy_1=e^{rx}. Seek y2=v(x)erxy_2 = v(x)e^{rx} (reduction of order). (1) Then y2=(v+rv)erxy_2'=(v'+rv)e^{rx}, y2=(v+2rv+r2v)erxy_2''=(v''+2rv'+r^2v)e^{rx}. Substitute: a(v+2rv+r2v)+b(v+rv)+cv=0a(v''+2rv'+r^2v)+b(v'+rv)+cv=0 av+(2ar+b)v+(ar2+br+c)v=0.a v'' + (2ar+b)v' + (ar^2+br+c)v = 0. (1) The vv-coefficient is 00 (root), and 2ar+b=02ar+b=0 (double root r=b/2a\Rightarrow r=-b/2a). (1) So av=0v=0v=C1+C2xa v''=0 \Rightarrow v''=0 \Rightarrow v = C_1 + C_2 x; the new piece is v=xv=x, giving y2=xerxy_2 = x e^{rx}. (1)

(b) Characteristic: r24r+13=0r=4±16522=2±3ir^2-4r+13=0 \Rightarrow r = \frac{4\pm\sqrt{16-52}}{2} = 2\pm 3i. (2) Complex solutions: e(2+3i)x,e(23i)xe^{(2+3i)x}, e^{(2-3i)x}. Using Euler eiθ=cosθ+isinθe^{i\theta}=\cos\theta+i\sin\theta: (1) e2xe±3ix=e2x(cos3x±isin3x).e^{2x}e^{\pm 3ix} = e^{2x}(\cos 3x \pm i\sin 3x). Real combinations (sum/difference over 2, 2i) give e2xcos3xe^{2x}\cos3x and e2xsin3xe^{2x}\sin3x. (1) y=e2x(C1cos3x+C2sin3x).(2)\boxed{y = e^{2x}(C_1\cos 3x + C_2\sin 3x)}. \quad (2)


Question 3

(a) L{eat}=0esteatdt=0e(sa)tdt.\mathcal{L}\{e^{at}\} = \int_0^\infty e^{-st}e^{at}\,dt = \int_0^\infty e^{-(s-a)t}\,dt. (1) =[1sae(sa)t]0=0(1sa)=1sa.(1)= \left[\frac{-1}{s-a}e^{-(s-a)t}\right]_0^\infty = 0 - \left(\frac{-1}{s-a}\right) = \frac{1}{s-a}. \quad (1) The limit at \infty is 00 only if sa>0s-a>0, so ROC is s>as>a. (1)

(b) L{f}=0estf(t)dt.\mathcal{L}\{f'\}=\int_0^\infty e^{-st}f'(t)\,dt. Integrate by parts, u=est,dv=fdtu=e^{-st}, dv=f'dt: (1) =[estf(t)]0+s0estf(t)dt.=\Big[e^{-st}f(t)\Big]_0^\infty + s\int_0^\infty e^{-st}f(t)\,dt. (1) Boundary term: at \infty, 0\to 0 (for ss in ROC); at 00, f(0)-f(0). (1) =f(0)+sF(s)=sF(s)f(0).(1)= -f(0) + sF(s) = sF(s)-f(0). \quad (1)

(c) Transform y3y=0y'-3y=0: sYy(0)3Y=0(s3)Y=2sY-y(0)-3Y=0 \Rightarrow (s-3)Y = 2. (1) Y=2s3.(1)Y = \frac{2}{s-3}. \quad (1) Invert (part a with a=3a=3): y=2e3ty=2e^{3t}. (1)


Question 4

(a) Transform: s2Ysy(0)y(0)+Y=L{uπ}=eπsss^2Y - sy(0)-y'(0) + Y = \mathcal{L}\{u_\pi\} = \dfrac{e^{-\pi s}}{s}. (2) With zero initial conditions: (s2+1)Y=eπssY=eπss(s2+1).(2)(s^2+1)Y = \frac{e^{-\pi s}}{s} \Rightarrow Y = \frac{e^{-\pi s}}{s(s^2+1)}. \quad (2)

(b) Partial fractions: 1s(s2+1)=1sss2+1\dfrac{1}{s(s^2+1)} = \dfrac{1}{s} - \dfrac{s}{s^2+1}. (2) Inverse of this factor: 1cost1 - \cos t. (1) The eπse^{-\pi s} triggers the second shift theorem: multiply by uπ(t)u_\pi(t) and replace ttπt\to t-\pi: (1) y(t)=uπ(t)[1cos(tπ)].(1)y(t) = u_\pi(t)\big[1 - \cos(t-\pi)\big]. \quad (1) Piecewise: y(t)={0,0t<π1cos(tπ)=1+cost,tπ(1)\boxed{y(t) = \begin{cases} 0, & 0\le t<\pi \\ 1 - \cos(t-\pi) = 1+\cos t, & t\ge\pi \end{cases}} \quad (1)

(c) Since cos(tπ)=cost\cos(t-\pi) = -\cos t, for t>πt>\pi: y(t)=1+cost.(2)y(t) = 1 + \cos t. \quad (2)


Question 5

(a) det(AλI)=(1λ)24=0(1λ)=±2λ1=3, λ2=1\det(A-\lambda I) = (1-\lambda)^2 - 4 = 0 \Rightarrow (1-\lambda)=\pm2 \Rightarrow \lambda_1=3,\ \lambda_2=-1. (2) For λ=3\lambda=3: (A3I)=(2222)v1=(1,1)T(A-3I)=\begin{pmatrix}-2&2\\2&-2\end{pmatrix}\Rightarrow v_1=(1,1)^T. (1) For λ=1\lambda=-1: (2222)v2=(1,1)T\begin{pmatrix}2&2\\2&2\end{pmatrix}\Rightarrow v_2=(1,-1)^T. (1) x(t)=C1e3t(11)+C2et(11).(1)\mathbf{x}(t)=C_1 e^{3t}\begin{pmatrix}1\\1\end{pmatrix} + C_2 e^{-t}\begin{pmatrix}1\\-1\end{pmatrix}. \quad (1)

(b) Eigenvalues real, opposite signs (3>03>0, 1<0-1<0) ⇒ saddle point, which is unstable. (3)

(c) For x=Ax\mathbf{x}'=A\mathbf{x}, let T=trAT=\operatorname{tr}A, D=detAD=\det A, discriminant Δ=T24D\Delta=T^2-4D.

  • D<0D<0: saddle (unstable).
  • D>0, Δ>0D>0,\ \Delta>0: node (stable if T<0T<0, unstable if T>0T>0).
  • D>0, Δ<0D>0,\ \Delta<0: spiral (stable if T<0T<0, unstable if T>0T>0); T=0T=0 ⇒ centre. (2)

Question 6

(a)

def euler(f, x0, y0, h, n):
    xs, ys = [x0], [y0]
    x, y = x0, y0
    for _ in range(n):
        y = y + h * f(x, y)
        x = x + h
        xs.append(x)
        ys.append(y)
    return xs, ys

Marks: correct update rule yy+hf(x,y)y\leftarrow y+h f(x,y) (2), loop/n steps (1), returns both lists (1).

(b) f(x,y)=yf(x,y)=y, h=0.5h=0.5:

  • Step 1: y1=1+0.5(1)=1.5y_1 = 1 + 0.5(1) = 1.5.
  • Step 2: y2=1.5+0.5(1.5)=2.25y_2 = 1.5 + 0.5(1.5) = 2.25.

Euler estimate y(1)2.25y(1)\approx 2.25; exact e2.71828e\approx 2.71828. Underestimate (error 0.468\approx0.468). (2)


[
  {"claim":"Q1b solution y=sin x /x^2 satisfies ODE and IC",
   "code":"x=symbols('x'); y=sin(x)/x**2; lhs=diff(y,x)+2/x*y; result=(simplify(lhs-cos(x)/x**2)==0) and (y.subs(x,pi)==0)"},
  {"claim":"Q2b roots of char eqn are 2+-3i",
   "code":"r=symbols('r'); sols=solve(r**2-4*r+13,r); result=set(sols)==set([2+3*I,2-3*I])"},
  {"claim":"Q4 partial fraction 1/(s(s^2+1))=1/s - s/(s^2+1)",
   "code":"s=symbols('s'); result=simplify(1/(s*(s**2+1)) - (1/s - s/(s**2+1)))==0"},
  {"claim":"Q5 eigenvalues of A are 3 and -1",
   "code":"A=Matrix([[1,2],[2,1]]); result=sorted(A.eigenvals().keys())==[-1,3]"},
  {"claim":"Q6 two-step Euler for y'=y gives 2.25",
   "code":"y=1.0; h=0.5\nfor _ in range(2): y=y+h*y\nresult=abs(y-2.25)<1e-9"}
]