# 1 Dimentional Ordinary Differential Equations (ODE)


## Exponential Model

\begin{equation}
\begin{split}
\frac{dx}{dt} =&  r\cdot x
\end{split}
\end{equation}

Initial value problem $x(0) = X_0$ (inital conditions). Solution is given by

$$x(t)=X_0\exp\left(r\cdot t\right)$$





```python
import numpy as np
import pandas as pd
from functools import partial
from scipy.integrate import odeint


def exponential_growth(x, t, r):
    """
        Exponential Growth model.
    """    
    dxdt = r*x
    
    return dxdt

```


```python
initial_conditions = [10, 100, 300, 500]

import matplotlib.pyplot as plt

t_span = np.linspace(0, 5, num=100)
r_values =[ -2,  0,  2]

fig, ax = plt.subplots(1,1, figsize=(15.5, 7))
for ic in initial_conditions:
    y =  odeint(exponential_growth, y0=ic, t=t_span, args=(r_values[0],) )
    ax.plot(t_span, y, label='x(0)={}'.format(ic))
    ax.set_xlabel('Time')
    ax.set_ylabel('x(t)')
ax.set_title('r={}'.format(r_values[0]))
ax.legend()

##############################################

fig, ax = plt.subplots(1,2, figsize=(15.5, 7))
for ic in initial_conditions:
    y =  odeint(exponential_growth, y0=ic, t=t_span, args=(r_values[0],) )
    ax[0].plot(t_span, y, label='x(0)={}'.format(ic))
    ax[0].set_xlabel('Time')
    ax[0].set_ylabel('x(t)')
    ax[0].set_title('r={}'.format(r_values[0]))


    y =  odeint(exponential_growth, y0=ic, t=t_span, args=(r_values[-1],) )
    ax[1].plot(t_span, y, label='x(0)={}'.format(ic))
    ax[1].set_xlabel('Time')
    ax[1].set_ylabel('x(t)')
    ax[1].set_title('r={}'.format(r_values[-1]))
    ax[1].set_ylim([0, 1000])
```

## Logistic Model

\begin{equation}
\begin{split}
\frac{dx}{dt} =&  r\cdot x\cdot \left(1-\frac{x}{K}\right)
\end{split}
\end{equation}


```python
xlimit = (-1.3, 1.3)
ylimit = (-0.5, 0.5)


def logistic_growth(x, t, r, K):
    """
        Logistic Growth model.
    """    
    dxdt = r*x*(1-x/K)
    
    return dxdt

initial_conditions = [10, 100, 300, 400]

import matplotlib.pyplot as plt

t_span = np.linspace(0, 5, num=100)
r_values =[ -2,  0,  2]
K = 500

fig, ax = plt.subplots(1,1, figsize=(15.5, 7))
for ic in initial_conditions:
    y =  odeint(logistic_growth, y0=ic, t=t_span, args=(r_values[0],500) )
    ax.plot(t_span, y, label='x(0)={}'.format(ic))
    ax.set_xlabel('Time')
    ax.set_ylabel('x(t)')
ax.set_title('r={}'.format(r_values[0]))
ax.legend()

##############################################

fig, ax = plt.subplots(1,1, figsize=(15.5, 7))
for ic in initial_conditions:
    y =  odeint(logistic_growth, y0=ic, t=t_span, args=(r_values[0],500) )
    ax.plot(t_span, y, label='x(0)={}'.format(ic))
    ax.set_xlabel('Time')
    ax.set_ylabel('x(t)')
    ax.set_title('r={}'.format(r_values[0]))

    y =  odeint(logistic_growth, y0=ic, t=t_span, args=(r_values[-1],500) )
    ax.plot(t_span, y, label='x(0)={}'.format(ic), linestyle='--')
    ax.set_xlabel('Time')
    ax.set_ylabel('x(t)')
ax.set_title('continious line (-) r=-2 | non-continuos line (--): r=2')


```


```python

```

2448c120d9c4be4c57a8c62be5b8bc6334a38c0d
ipynb
Jupyter Notebook
1D SYSTEMS/example.ipynb
ChaosDonkey06/MODSIM_IBIO
e2ce70538aaba3b01f22cf037db21a80316a802f
Apache-2.0
1D SYSTEMS/example.ipynb
ChaosDonkey06/MODSIM_IBIO
e2ce70538aaba3b01f22cf037db21a80316a802f
Apache-2.0
1D SYSTEMS/example.ipynb
ChaosDonkey06/MODSIM_IBIO
e2ce70538aaba3b01f22cf037db21a80316a802f
Apache-2.0
Qwen/Qwen-72B
1. YES
2. YES