Numerical Methods · Unit 9
Ordinary Differential Equations
Exam-focused notes for Ordinary Differential Equations (Numerical Methods, BIT203): what the TU syllabus asks and how it has actually been tested, with 9 solved past questions from this unit.
Ordinary Differential Equations in short
Many laws of science are written as differential equations. Most of them cannot be solved by formula. Numerical methods build the solution step by step from a known starting value.
What this unit covers
- Initial value problems and solution methods
- Euler's method for ODE solving
- Heun's method for ODE solving
- Runge-Kutta fourth order method
- Boundary value problems and initial value problems
- Shooting method for boundary value problems
- Higher order differential equation solving
Runge-Kutta fourth order method
2082 · 5 marks
Solve $\frac{dy}{dx} = x^2 + y$, with $y(0) = 1$ for $x = 1.5$, using RK fourth order method. [5]
Show solved answerHide answer
RK4 Method: dy/dx = x² + y, y(0) = 1, find y(1.5)
Given data
- ODE: $\dfrac{dy}{dx} = f(x,y) = x^2 + y$
- Initial condition: $x_0 = 0$, $y_0 = 1$
- Target: $y$ at $x = 1.5$
- Step size (chosen): $h = 0.5$, giving 3 steps: $0 \to 0.5 \to 1.0 \to 1.5$
RK4 formulas
$$k_1 = h f(x_n, y_n),\quad k_2 = h f!\left(x_n+\tfrac h2, y_n+\tfrac{k_1}{2}\right)$$ $$k_3 = h f!\left(x_n+\tfrac h2, y_n+\tfrac{k_2}{2}\right),\quad k_4 = h f(x_n+h, y_n+k_3)$$ $$y_{n+1} = y_n + \tfrac16(k_1 + 2k_2 + 2k_3 + k_4)$$
Step 1: $x_0=0 \to x_1=0.5$, $y_0=1$
$$k_1 = 0.5(0^2+1) = 0.5$$ $$k_2 = 0.5\big(0.25^2 + (1+0.25)\big) = 0.5(0.0625+1.25) = 0.65625$$ $$k_3 = 0.5\big(0.0625 + (1+0.328125)\big) = 0.5(1.390625) = 0.6953125$$ $$k_4 = 0.5\big(0.25 + (1+0.6953125)\big) = 0.5(1.9453125) = 0.9726563$$
$$y_1 = 1 + \tfrac16(0.5 + 1.3125 + 1.390625 + 0.9726563) = 1 + \tfrac16(4.1757813)$$ $$\boxed{y_1 = 1.6959635}$$
Step 2: $x_1=0.5 \to x_2=1.0$, $y_1=1.6959635$
$$k_1 = 0.5(0.25 + 1.6959635) = 0.9729818$$ $$k_2 = 0.5\big(0.5625 + (1.6959635+0.4864909)\big) = 0.5(2.7449544) = 1.3724772$$ $$k_3 = 0.5\big(0.5625 + (1.6959635+0.6862386)\big) = 0.5(2.9447021) = 1.4723511$$ $$k_4 = 0.5\big(1.0 + (1.6959635+1.4723511)\big) = 0.5(4.1683146) = 2.0841573$$
$$y_2 = 1.6959635 + \tfrac16(0.9729818 + 2.7449544 + 2.9447022 + 2.0841573)$$ $$= 1.6959635 + \tfrac16(8.7467957) = 1.6959635 + 1.4577993$$ $$\boxed{y_2 = 3.1537628}$$
Step 3: $x_2=1.0 \to x_3=1.5$, $y_2=3.1537628$
$$k_1 = 0.5,f(1.0, 3.1537628) = 0.5(1.0 + 3.1537628) = 0.5(4.1537628) = 2.0768814$$
$y_2 + k_1/2 = 3.1537628 + 1.0384407 = 4.1922035$ $$k_2 = 0.5,f(1.25, 4.1922035) = 0.5(1.5625 + 4.1922035) = 0.5(5.7547035) = 2.8773518$$
$y_2 + k_2/2 = 3.1537628 + 1.4386759 = 4.5924387$ $$k_3 = 0.5,f(1.25, 4.5924387) = 0.5(1.5625 + 4.5924387) = 0.5(6.1549387) = 3.0774693$$
$y_2 + k_3 = 3.1537628 + 3.0774693 = 6.2312321$ $$k_4 = 0.5,f(1.5, 6.2312321) = 0.5(2.25 + 6.2312321) = 0.5(8.4812321) = 4.2406161$$
$$y_3 = 3.1537628 + \tfrac16\big(2.0768814 + 2(2.8773518) + 2(3.0774693) + 4.2406161\big)$$ $$= 3.1537628 + \tfrac16(2.0768814 + 5.7547036 + 6.1549386 + 4.2406161)$$ $$= 3.1537628 + \tfrac16(18.2271397)$$ $$= 3.1537628 + 3.0378566$$ $$\boxed{y_3 = y(1.5) \approx 6.1916}$$
Result
$$y(1.5) \approx 6.1916$$
(Exact solution $y = 3e^x - x^2 - 2x - 2$ gives $y(1.5) = 3e^{1.5} - 2.25 - 3 - 2 = 13.4450 - 7.25 = 6.1950$, confirming the RK4 result to about 3 significant figures.)
Boundary value problems and initial value problems
2082 · 5 marks
Explain boundary value problem with example. Describe how higher order differential equation can be solved. [2+3]
Shooting method for boundary value problems
2080 · 10 marks
Solve the following ordinary differential equation using shooting method. $y'' + xy' - xy = 2x$ with boundary conditions $y(0) = 1$ and $y(2) = 10$ [10]
2078 · 10 marks
What do you mean by boundary value problem? Use shootuing method, solve the equation: y'' = 6x², with y(0) = 1 and y(1) = 2 in the interval (0, 1) for y(0.5) taking h = 0.5[10]
Show solved answerHide answer
Boundary Value Problem and Shooting Method
Given
- ODE: $y'' = 6x^2$
- Boundary conditions: $y(0) = 1$, $y(1) = 2$
- Interval: $(0, 1)$
- Step size: $h = 0.5$
- Required: $y(0.5)$
Boundary Value Problem (Definition)
A boundary value problem (BVP) is a differential equation together with conditions specified at two or more different points (the boundaries of the domain), rather than all at a single point.
General second order form: $$y'' = f(x, y, y'), \quad a \le x \le b, \quad y(a) = \alpha, \ \ y(b) = \beta$$
Shooting Method (Idea)
The shooting method converts a BVP into an initial value problem (IVP) by guessing the unknown initial slope $y'(0) = t$, integrating forward, and adjusting $t$ until the far boundary condition $y(b) = \beta$ is met. Since this ODE is linear, only two trial slopes (or the decomposition method) are needed, and the correct $t$ follows by linear interpolation.
Solution
Reduce to a first-order system with $y_1 = y$, $y_2 = y'$: $$y_1' = y_2, \qquad y_2' = 6x^2$$ with $y_1(0) = 1$, $y_2(0) = t$ (unknown).
Use Euler's method, $h = 0.5$, two steps ($x = 0, 0.5, 1.0$).
Trial 1: guess $t = t_1 = 0$
| $x$ | $y_1$ | $y_2$ | $y_2'=6x^2$ |
|---|---|---|---|
| 0.0 | 1.0000 | 0.0000 | 0.0 |
| 0.5 | $1+0.5(0)=1.0000$ | $0+0.5(0)=0.0000$ | $6(0.25)=1.5$ |
| 1.0 | $1+0.5(0)=1.0000$ | $0+0.5(1.5)=0.75$ | -- |
So with $t_1 = 0$: $y(1) = 1.0000 \equiv \beta_1$
Trial 2: guess $t = t_2 = 1$
| $x$ | $y_1$ | $y_2$ | $y_2'=6x^2$ |
|---|---|---|---|
| 0.0 | 1.0000 | 1.0000 | 0.0 |
| 0.5 | $1+0.5(1)=1.5000$ | $1+0.5(0)=1.0000$ | $1.5$ |
| 1.0 | $1.5+0.5(1)=2.0000$ | $1+0.5(1.5)=1.75$ | -- |
So with $t_2 = 1$: $y(1) = 2.0000 \equiv \beta_2$
Linear interpolation for correct slope
Target $\beta = 2$. Since the ODE is linear: $$t = t_1 + (t_2 - t_1)\cdot \frac{\beta - \beta_1}{\beta_2 - \beta_1} = 0 + (1-0)\cdot\frac{2 - 1}{2 - 1} = 1$$
Thus the correct slope is $t = 1$, and Trial 2 is exactly the required solution.
Read off $y(0.5)$
From Trial 2 at $x = 0.5$: $$\boxed{y(0.5) = 1.5000}$$
Verification with Exact Solution
Integrating twice: $$y' = 2x^3 + C_1, \qquad y = \frac{x^4}{2} + C_1 x + C_2$$
Apply $y(0)=1 \Rightarrow C_2 = 1$. Apply $y(1)=2 \Rightarrow \tfrac12 + C_1 + 1 = 2 \Rightarrow C_1 = \tfrac12$.
$$y = \frac{x^4}{2} + \frac{x}{2} + 1$$
Exact value: $$y(0.5) = \frac{(0.5)^4}{2} + \frac{0.5}{2} + 1 = \frac{0.0625}{2} + 0.25 + 1 = 0.03125 + 1.25 = 1.28125$$
Note: The Euler shooting result $y(0.5) = 1.5$ differs from the exact $1.28125$. This gap is due to the very large step size $h = 0.5$ used by Euler's method (only two steps). Euler's method reproduces the correct boundary values $y(0)=1$ and $y(1)=2$ exactly because the slope-parameter interpolation is exact for the linear problem, but the intermediate point $y(0.5)$ carries the local truncation error of Euler's scheme. The method-consistent answer requested by the problem (using shooting with $h=0.5$) is:
$$y(0.5) \approx 1.5$$
while the true analytic value is $1.28125$.
0 · 5 marks
How boundary value problems differs from initial value problems? Discuss shooting method for solving boundary value problem. [5]
Euler's method for ODE solving
2080 · 5 marks
Solve the following differential equation $$\frac{dy}{dx} = 3x + \frac{y}{2}$$ with $y(0) = 1$ for $x = 0.2$ $(h = 0.1)$ using Euler's Method. [5]
2078 · 5 marks
Given the equation y′=3x2+1y' = 3x^2 + 1y′=3x2+1 with y(1) = 2, estimate y(2) by Euler's Method using h = 0.2. [5]
0 · 5 marks
Approximate the solution of y'=2x+y, y(0)=1 using Euler's method with step size of 0.1. Approximate the value of y(0.4). [5]
Heun's method for ODE solving
2079 · 5 marks
Find the approximate value of y when x = 0.6 of $dy/dx = 1-2xy$, given that y = 0 when x = 0 with h=0.2 using Heun's method. [5]
Make Unit 9 stick
Practice BIT203 with flashcards & quizzes