Skip to content

Latest commit

 

History

History
128 lines (100 loc) · 3.6 KB

README.md

File metadata and controls

128 lines (100 loc) · 3.6 KB

COE 352 Homework 3

Introduction

This homework uses the following IVP:

$$\frac{dy}{dt} = -\alpha y\\$$ $$y(0) = 1 \quad \quad \alpha > 0 \quad \quad 0 ≤ t ≤ T$$

Calculating the exact solution

To calculate the exact solution, the following logic was used:

$$\frac{dy}{dt} = -\alpha y$$ $$\frac{dy}{y} = -\alpha dt$$ $$\int {\frac{dy}{y}} = \int {-\alpha dt}$$ $$ln(y) + C = - \alpha t$$ $$y = e^ {- \alpha t + C} = Ce^ {- \alpha t}$$

Then using the initial condition y(0) = 1, we get our exact solution:

$$y = e^ {- \alpha t}$$

Forward Euler

Now, we will derive the update equation using Forward Euler time discretization

Forward Euler:

$$y_{n+1} = y_n + \Delta t \cdot f(t_n, y_n)$$

where

$$f(t_n, y_n) = \frac{dy}{dt} = -\alpha y\\$$

We get:

$$y_{n+1} = y_n + \Delta t \cdot f(t_n, y_n) = y_n - \Delta t \alpha y_n = y_n (1 - \alpha \Delta t)$$

Therefore, our update equation using Forward Euler time discretization is:

$$y_{n+1} = y_n (1 - \alpha \Delta t)$$

Furthermore, we know that Forward Euler time discretization loses stability with growth factors greater than 1, so we can derive a stability condition as follows:

$$|(1 - \alpha \Delta t)| ≤ 1$$

So, our stability condition is:

$$0 ≤ \alpha \Delta t ≤ 2$$

The python script to find the numerical solution using this method is forwardEuler.py.

The Plot of the numerical and exact solution for various values Δt, using α = 1:

Forward Euler Plot

Using only convergent Δt's: Forward Euler Plot Convergent

Backward Euler

Now, we will derive the update equation using Backward Euler time discretization Backward Euler:

$$y_{n+1} = y_n + \Delta t \cdot f(t_{n+1} y_{n+1})$$

Using

$$y_{n+1} = y_n + \Delta t f(t_{n+1} y_{n+1}) = y_n - \alpha \Delta t y_{n+1}$$

We can then derive our Backward Euler update equation:

$$y_{n+1} = \frac {y_n}{1 + \alpha \Delta t}$$

It should be noted that the backward euler method for this IVP is unconditionally stable, as the stability condition is

$$|\frac {1}{1 + \alpha \Delta t}| ≤ 1$$

Which is always satisfied as both Δt and α are always positive.

The python script to find the numerical solution using this method is backwardEuler.py.

The Plot of the numerical and exact solution for various values Δt, using α = 1:

Backward Euler Plot

Trapezoidal Method

Now, we will derive the update equation using Trapezoidal Method time discretization Trapezoidal Method:

$$y_{n+1} = y_n + \frac {\Delta t}{2} (f(t_{n} y_{n}) + f(t_{n+1} y_{n+1}) )$$

Using

$$y_{n+1} = y_n + \frac {\Delta t}{2} (- \alpha y_{n} - \alpha y_{n+1}) \quad => \quad y_{n+1} (1 + \frac {\alpha \Delta t}{2}) = y_{n} (1 - \frac {\alpha \Delta t}{2})$$

We can then derive our Trapezoidal Method update equation:

$$y_{n+1} = y_n \frac {(1 - \frac {\alpha \Delta t}{2})}{(1 + \frac {\alpha \Delta t}{2})}$$

The python script to find the numerical solution using this method is trapezoidal.py.

The Plot of the numerical and exact solution for various values Δt, using α = 1:

Trapezoidal Method Plot