Numerical Method Ā· Unit 5 Ā· 8 hrs
Solution of Ordinary Differential Equations
Exam-focused notes for Solution of Ordinary Differential Equations (Numerical Method, CSC212): what the TU syllabus asks and how it has actually been tested, with 12 solved past questions from this unit.
Solution of Ordinary Differential Equations in short
An ordinary differential equation (ODE) specifies how a function changes rather than giving the function itself; this chapter develops step-by-step numerical methods that reconstruct the function from its rate of change, given a starting value.
What this unit covers
- Review of differential equations
- Initial value problem
- Taylor series method
- Picard's method
- Euler's method and its accuracy
- Heun's method
- Runge-Kutta methods
- Solving System of ordinary differential equations
- Solution of the higher order equations
- Boundary value problems
- Shooting method and its algorithm
Review of differential equations
2081 Ā· 5 marks
What is differential equation? Differentiate between ODE and PDE with example. [5]
Show solved answerHide answer
Differential Equation, ODE and PDE
Differential Equation
An equation which uses differential calculus to express relationship between variables is known as a differential equation.
In other words, a differential equation is an equation that contains one or more derivatives of a dependent variable with respect to one or more independent variables.
Types of Differential Equations
Differential equations are of two types:
1. Ordinary Differential Equation (ODE)
A differential equation with a single independent variable (i.e., the quantity with respect to which the dependent variable is differentiated) is called an Ordinary Differential Equation (ODE).
Example:
$$\frac{dy}{dx} + 2y = x$$
Here, y is the dependent variable and x is the only independent variable. Since there is only one independent variable, this is an ODE.
Another example:
$$\frac{d^2y}{dx^2} + 3\frac{dy}{dx} + y = 0$$
2. Partial Differential Equation (PDE)
A differential equation with more than one independent variable is called a Partial Differential Equation (PDE).
Example:
$$\frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2} = 0$$
Here, u is the dependent variable and x, y are two independent variables. Since there are more than one independent variable, this is a PDE.
Comparison Table: ODE vs PDE
| Feature | ODE | PDE |
|---|---|---|
| Independent Variables | Single independent variable | More than one independent variable |
| Derivative Type | Ordinary derivatives | Partial derivatives |
| Complexity | Relatively simpler | More complex |
| Notation | $\frac{dy}{dx}$, $\frac{d^2y}{dx^2}$ | $\frac{\partial u}{\partial x}$, $\frac{\partial^2 u}{\partial x^2}$ |
| Example | $\frac{dy}{dx} + 2y = x$ | $\frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2} = 0$ |
Note: The relationship between dependent and independent variables that satisfies a differential equation is called the solution of the differential equation.
Runge-Kutta methods
2081 Ā· 5 marks
Solve $\frac{dy}{dx} = \frac{x}{y}$, $y(0) = 1$, at $x = 0.4$ using Runge-Kutta's 4th order method. [5]
Show solved answerHide answer
Runge-Kutta 4th Order Method
Given Data
$$\frac{dy}{dx} = f(x,y) = \frac{x}{y}, \quad y_0 = 1 \text{ at } x_0 = 0, \quad \text{find } y(0.4)$$
Step size: $h = 0.4$ (single step).
RK4 Formulas
$$k_1 = h f(x_0, y_0)$$ $$k_2 = h f\left(x_0+\tfrac{h}{2}, y_0+\tfrac{k_1}{2}\right)$$ $$k_3 = h f\left(x_0+\tfrac{h}{2}, y_0+\tfrac{k_2}{2}\right)$$ $$k_4 = h f\left(x_0+h, y_0+k_3\right)$$ $$y_1 = y_0 + \tfrac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4)$$
Calculation
$k_1$: $$k_1 = 0.4 \cdot f(0, 1) = 0.4 \cdot \frac{0}{1} = 0$$
$k_2$: $$k_2 = 0.4 \cdot f(0.2, \ 1+0) = 0.4 \cdot \frac{0.2}{1} = 0.08$$
$k_3$: $$k_3 = 0.4 \cdot f(0.2, \ 1+0.04) = 0.4 \cdot \frac{0.2}{1.04} = 0.4 \cdot 0.192308 = 0.076923$$
$k_4$: $$k_4 = 0.4 \cdot f(0.4, \ 1+0.076923) = 0.4 \cdot \frac{0.4}{1.076923} = 0.4 \cdot 0.371429 = 0.148571$$
Final Result
$$y_1 = 1 + \frac{1}{6}\big(0 + 2(0.08) + 2(0.076923) + 0.148571\big)$$
$$= 1 + \frac{1}{6}\big(0 + 0.16 + 0.153846 + 0.148571\big)$$
$$= 1 + \frac{1}{6}(0.462418) = 1 + 0.077070$$
$$\boxed{y(0.4) \approx 1.0771}$$
Verification (Exact Solution)
Separating variables: $y,dy = x,dx \Rightarrow \tfrac{y^2}{2} = \tfrac{x^2}{2} + C$. With $y(0)=1$, $C = \tfrac12$, so $y = \sqrt{1+x^2}$.
At $x=0.4$: $y = \sqrt{1.16} = 1.07703$.
The RK4 result $1.0771$ matches the exact value very closely.
2079 Ā· 5 marks
Solve the following differential equation for $0 \leq x \leq 1$ taking $h = 0.5$ using Runge Kutta 4th order method.
$$y'(x) + y = 3x \quad \text{with} \quad y(0) = 2$$
[5]
Show solved answerHide answer
Runge-Kutta 4th Order Method
Given
- ODE: $y'(x) + y = 3x \Rightarrow y' = f(x,y) = 3x - y$
- Initial condition: $y(0) = 2$
- Step size: $h = 0.5$
- Interval: $0 \le x \le 1$
- Number of steps: 2 (from $x=0$ to $x=1$)
RK4 Formulas
$$k_1 = h,f(x_n, y_n), \quad k_2 = h,f\left(x_n+\tfrac{h}{2}, y_n+\tfrac{k_1}{2}\right)$$ $$k_3 = h,f\left(x_n+\tfrac{h}{2}, y_n+\tfrac{k_2}{2}\right), \quad k_4 = h,f(x_n+h, y_n+k_3)$$ $$y_{n+1} = y_n + \tfrac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4)$$
with $f(x,y) = 3x - y$.
Solution
Iteration 1: $x_0 = 0$, $y_0 = 2$
$$k_1 = 0.5,(3(0) - 2) = 0.5(-2) = -1.0$$
$$k_2 = 0.5,f(0.25,\ 2 - 0.5) = 0.5,(0.75 - 1.5) = 0.5(-0.75) = -0.375$$
$$k_3 = 0.5,f(0.25,\ 2 - 0.1875) = 0.5,(0.75 - 1.8125) = 0.5(-1.0625) = -0.53125$$
$$k_4 = 0.5,f(0.5,\ 2 - 0.53125) = 0.5,(1.5 - 1.46875) = 0.5(0.03125) = 0.015625$$
$$y_1 = 2 + \tfrac{1}{6}(-1.0 + 2(-0.375) + 2(-0.53125) + 0.015625)$$ $$= 2 + \tfrac{1}{6}(-1.0 - 0.75 - 1.0625 + 0.015625) = 2 + \tfrac{1}{6}(-2.796875)$$ $$= 2 - 0.466146 = \boxed{1.533854}$$
$$y(0.5) \approx 1.5339$$
Iteration 2: $x_1 = 0.5$, $y_1 = 1.533854$
$$k_1 = 0.5,f(0.5,\ 1.533854) = 0.5,(1.5 - 1.533854) = 0.5(-0.033854) = -0.016927$$
$$k_2 = 0.5,f(0.75,\ 1.533854 - 0.008464) = 0.5,(2.25 - 1.525390) = 0.5(0.724610) = 0.362305$$
$$k_3 = 0.5,f(0.75,\ 1.533854 + 0.181153) = 0.5,(2.25 - 1.715007) = 0.5(0.534993) = 0.267497$$
$$k_4 = 0.5,f(1.0,\ 1.533854 + 0.267497) = 0.5,(3.0 - 1.801351) = 0.5(1.198649) = 0.599325$$
$$y_2 = 1.533854 + \tfrac{1}{6}(-0.016927 + 2(0.362305) + 2(0.267497) + 0.599325)$$ $$= 1.533854 + \tfrac{1}{6}(-0.016927 + 0.724610 + 0.534993 + 0.599325)$$ $$= 1.533854 + \tfrac{1}{6}(1.842001) = 1.533854 + 0.307000$$ $$= \boxed{1.840854}$$
$$y(1.0) \approx 1.8409$$
Summary Table
| $x$ | $y$ |
|---|---|
| $0.0$ | $2.0000$ |
| $0.5$ | $1.5339$ |
| $1.0$ | $1.8409$ |
Check (exact): $y = 3x - 3 + 5e^{-x}$; at $x=1$: $y = 0 + 5e^{-1} = 1.8394$. RK4 value $1.8409$ agrees closely.
2075 Ā· 5 marks
From the following differential equation estimate y(1) using RK 4th order method.
$$\frac{dy}{dx} + 2x^2y = 4 \quad \text{with} \quad y(0) = 1$$
[Take $h = 0.5$] [5]
Taylor series method
2080 Ā· 5 marks
Approximate the solution of $y' = 3x^2$, $y(1) = 1$ using Taylor's series method using first four terms. Approximate the value of $y(2)$.
$$y' = 3x^2, \quad y(1) = 1$$
[5]
Heun's method
2080 Ā· 5 marks
Write down the program for solving ordinary differential equation using Heun's method. [5]
2079 Ā· 5 marks
Write down the program for solving ordinary differential equation using Heun's method. [5]
2078 Ā· 5 marks
Solve the following differential equation for $1 \leq x \leq 2$, taking $h = 0.25$ using Heunās method. $y'(x) + x^2y = 3x$, with $y(1) = 1$. [5]
Solution of the higher order equations
Euler's method and its accuracy
2077 Ā· 5 marks
Approximate the solution of $y' = 2x + y$, $y(0) = 1$ using Euler's method with step size 0.1. Approximate the value of $y(0.4)$. [5]
Shooting method and its algorithm
2077 Ā· 5 marks
How boundary value problems differs from initial value problems? Discuss shooting method for solving boundary value problem. [5]
2075 Ā· 10 marks
What is initial value problem and boundary value problem? Write an algorithm and program to solve the boundary value problem using shooting method.[10]
Make Unit 5 stick
Practice CSC212 with flashcards & quizzes