MTH3007b Weekly Problems 4
Original Documents: Problem Sheet / Provided Solutions
Vibes: …
Used Techniques:
- …
4.1. Isolating Variables in Linear and Nonlinear Equations
Question
Isolate in each of the following:
Part 1. :
Part 2. :
Part 3. - collect all terms on one side:
Part 4. - rearrange as a quadratic in :
Applying the quadratic formula:
This gives two branches; the physical one is selected by boundary/initial conditions.
4.2. Isolating the Next Step in Discrete Recurrences
Question
Isolate in each of the following:
Part 1. :
Part 2. - multiply both sides by and collect :
This is the Implicit Euler method for the decay ODE .
4.3. Implicit Euler for a Polynomial-Forced ODE
Question
Apply implicit Euler to and isolate .
Using implicit Euler, is approximated at :
Multiply through by and collect :
where .
Note: if , the denominator can become zero or negative for large , but implicit Euler is still more stable than explicit for stiff problems.
4.4. Predator-Prey Model
Question
Implement the Lotka-Volterra predator-prey system with , , , , initial conditions , , .
The Lotka-Volterra equations (predator-prey model) are:
where = prey population, = predator population.
import numpy as np
import matplotlib.pyplot as plt
prey_birth_rate = 1.2
predation_rate = 0.6
predator_death_rate = 0.8
predator_growth_rate = 0.3
time_start = 0.0
time_end = 30.0
time_step = 0.001
initial_state = np.array([2.0, 1.0])
def g(t: float, state: np.ndarray) -> np.ndarray:
prey_population, predator_population = state
return np.array([
prey_birth_rate * prey_population - predation_rate * prey_population * predator_population,
-predator_death_rate * predator_population + predator_growth_rate * prey_population * predator_population,
])
number_of_steps = int(round((time_end - time_start) / time_step))
t_values = np.zeros(number_of_steps + 1)
state_array = np.zeros((2, number_of_steps + 1))
t_values[0] = time_start
state_array[:, 0] = initial_state
for step_index in range(number_of_steps):
t_values[step_index + 1] = t_values[step_index] + time_step
state_array[:, step_index + 1] = (
state_array[:, step_index]
+ time_step * g(t_values[step_index], state_array[:, step_index])
)
plt.figure(figsize=(10, 4))
plt.subplot(1, 2, 1)
plt.plot(t_values, state_array[0, :], label='Prey')
plt.plot(t_values, state_array[1, :], label='Predator')
plt.xlabel('t')
plt.ylabel('Population')
plt.legend()
plt.title('Predator-Prey Dynamics')
plt.subplot(1, 2, 2)
plt.plot(state_array[0, :], state_array[1, :])
plt.xlabel('Prey population')
plt.ylabel('Predator population')
plt.title('Phase Plane')
plt.tight_layout()
plt.show()The system exhibits periodic oscillations: prey increase, then predators increase (eating prey), then prey decrease, then predators decrease (starving), and the cycle repeats. In the phase plane, the trajectory forms a closed orbit.
4.5. Stability Concepts
Question
Define and distinguish between: stability of an ODE, stability of a numerical method, convergence, consistency, and order of convergence.
Stability of an ODE: A differential equation is stable if small perturbations to the initial condition remain bounded over time. For a linear ODE , the solution is stable if and only if .
Stability of a method: A method is stable if small perturbations in the numerical solution do not grow unboundedly as the time-stepping proceeds. The stability condition depends on the method and the step size. The amplification factor (ratio for the test equation ) must satisfy for stability:
- Explicit Euler: , so stability requires .
- Implicit Euler: , so for all (unconditionally stable).
Consistency: A method is consistent if the truncation error goes to zero as . Equivalently, the discrete equations converge to the correct differential equation in the limit of fine resolution.
Convergence: A method is convergent if the numerical solution converges to the exact solution as . By the Lax Equivalence Theorem, for linear problems: consistency + stability convergence.
Order of convergence: The integer such that GTE . Methods with higher order require fewer steps to achieve the same accuracy.
| Method | Order | Stability |
|---|---|---|
| Explicit Euler | 1 | Conditional |
| Implicit Euler | 1 | Unconditional |
| Ralston | 2 | Conditional |
| Implicit Trapezoid | 2 | Unconditional |
| RK4 | 4 | Conditional |