# Lab 4: Solving ODE


```python
# IMPORTS
import numpy as np
import matplotlib.pyplot as plt
```

## Exercise 1

### Part 1

Write a function for Euler methods.


```python

```

### Part 2

Write a test for your Euler function


```python

```

## Exercise 2

### Part 1

Write a function for Runge Kutta 4 methods.


```python

```

### Part 2

Write a test for your Runge Kutta 4 function


```python

```

## Exercise 3

Use Euler/RK4's method to approximate/plot the solutions for each of the following initial-value problems. (Plot your solution for all the values of t)
1. $y'=e^{t-y}$, $0\leq t \leq 1$, $y(0)=1$, with $h=0.5$
2. $y'=\frac{1+t}{1+y}$, $1\leq t \leq 2$, $y(1)=2$, with $h=0.5$
3. $y' = t^{-2}(\sin2t - 2ty)$, $1 \leq t \leq 2$, $y(l) = 2$, with $h = 0.25 $
4. $ y' = 1+\frac{y}{t},\; 1 < t < 2, \; y(1) = 2$, with $h=0.25$


```python

```

## Exercise 4

Use Euler/RK4's method to approximate/plot the solutions for each of the following initial-value problem.
$$ y'= \frac{2-2ty}{t^2+1}, ~~~~ 1\leq t \leq 2, ~~~~ y(1)=2, ~~~~ h=0.25$$
The actual solutions to die initial-value is given here. Compute/plot the actual error of your approximation and bound the error.
$$y(t)=\frac{2t+2}{t^2+1}$$


```python

```

## Exercise 5

Given the initial-value problem 
$$y'=-y+t+1,  \; 0 \leq t \leq 5, \; y(0)=1$$
The exact solution is $y(t)=e^{-t}+t$.
Approximate y(6) using Euler/RK4's method with h = 0.2, h =0.1, and h = 0.05. 


```python

```

### Exericse 6

Lokta-Volterra Equations:
$$\begin{cases}
 & \displaystyle{\frac{dx}{dt} = \alpha x - \beta xy } \\
 & \displaystyle{\frac{dy}{dt} = \delta xy - \gamma y}
 \end{cases}$$
 where
* x is the number of prey
* y is the number of some predator
* $\alpha$, $\beta$, $\gamma$, $delta$ are positive real parameters describing the interaction of the two species.
* The prey are assumed to have an unlimited food supply and to reproduce exponentially, unless subject to predation; this exponential growth is represented in the equation above by the term $\alpha x$. 
* The rate of predation upon the prey is represented above by $\beta xy$. If either x or y is zero, then there can be no predation.
* $\delta xy$ represents the growth of the predator population.
* $\gamma y$ represents the loss rate of the predators due to either natural death or emigration, it leads to an exponential decay in the absence of prey


1. Solve the Lokta-Volterra equations with  the 4 different methods, with  $\alpha= 2/3$, $\beta = 4/3$, $\gamma = 1 = \delta$
2. Try another cool set of value and solve it.


```python

```

## Exercise 7
 
 Competitive Lotka–Volterra equations. 4 species competing for the same resource:
$$\frac{dx_i}{dt}=r_ix_i\left(1-\sum_{j=1}^4 \alpha_{ij}x_j\right)  \mbox{ for  } i=1,2,3,4 $$

* $r_{i}$ is the rate at which the species $i$ reproduce.
* $\alpha_{ij}$ represents the effect species j has on the population of species i.

1. Solve the Competitive Lokta-Volterrra equations with
  $$r = \begin{bmatrix}
          1\\0.72\\1.53\\1.27
         \end{bmatrix}, \enspace \alpha=\begin{bmatrix}
         1 & 1.09 & 1.52 & 0\\
         0& 1 & 0.44 & 1.36 \\
         2.33 & 0 & 1 & 0.47 \\
         1.21 & 0.51 & 0.35 & 1\\
         \end{bmatrix}$$
2.  Solve another cool one.


```python

```

## Exercise 8(COVID)

Pick the data from a state or country on [John Hopkins's Github](https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data), [John Hopkins dashboard](https://coronavirus.jhu.edu/map.html), [New York Time](https://www.nytimes.com/interactive/2021/us/covid-cases.html), [WHP](https://covid19.who.int/), and solve the SIRD model.

* $S(t)$: the number of individuals susceptible of contracting the infection at time $t$,
* $I(t)$: the number of individuals that are alive and infected at time t;
* $R(t)$: the cumulative number of individuals that recovered from the disease up to time t;
* $D(t)$: the cumulative number of individuals that deceased due to the disease, up to time t.

In addition, $N$ is the total number of people in the area at time $t$ with $N = S(t) + I(t) + R(t)$.
The SIRD model is given by the following expressions \cite{bai75}:
\begin{equation} 
\begin{split}
\dfrac{dS}{dt} &=  -\frac{\beta I S}{N}, \\ 
\dfrac{dI}{dt} &=  \frac{\beta I S}{N} - \gamma I - \mu I,\\
\dfrac{dR}{dt} &= \gamma I,\\
\dfrac{dD}{dt} &= \mu I,
\end{split}
\end{equation}

Pick $\beta$ between $0$ and $1$, $\gamma=1/14$, $\mu$ between $0$ and $0.05$.


```python

```

3b6432ac50d97a3545de09cd578c851a1c8267a9
ipynb
Jupyter Notebook
courses/m240/labs/lab_4.ipynb
amac-lfc/amac-lfc.github.io
d50f111c69fe4467bc868b53bdaa62d7efa84242
MIT
courses/m240/labs/lab_4.ipynb
amac-lfc/amac-lfc.github.io
d50f111c69fe4467bc868b53bdaa62d7efa84242
MIT
courses/m240/labs/lab_4.ipynb
amac-lfc/amac-lfc.github.io
d50f111c69fe4467bc868b53bdaa62d7efa84242
MIT
Qwen/Qwen-72B
1. YES
2. YES