```python
import numpy as np
from sympy.solvers import solve
from sympy import Symbol
import sympy

import matplotlib.pyplot as plt
```

#### Реализовать явный метод Эйлера


```python
def euler_method(f, t0, tn, tau, y0):
    
    eps = tau / 10000
    
    while t0 < tn and abs(t0 - tn) > eps:
        
        y0 += tau * f(t0, y0)
        
        t0 += tau
    
    return y0
    
```

##### Euler method testing 
Function: $y'(t) = t\sqrt{y(t)}$ \
Initials: $t_0=0, \ y_0=y(t_0)=y(0)=1$ \
Step: $\tau=0.1$


```python
t = np.arange(0, 11, 1, int)
y1 = np.array([euler_method(lambda t, y: t * y ** 0.5, 0, i, 0.1, 1) for i in t])
y2 = (t ** 2 + 4) ** 2 / 16

plt.plot(t, y1, label='estimated', marker='.')
plt.plot(t, y2, label='calculated', marker='.')
plt.grid(linestyle='--')

plt.title("Euler method")
plt.xlabel('t')
plt.ylabel('y')

plt.legend()

plt.show()

for _t, _y1, _y2 in zip(t, y1, y2):
    print(f"t = {_t}:\n\tEstimated: {_y1}\n\tCalculated: {_y2}\n")

```


```python
t = np.arange(0, 11, 1, int)
y1 = [euler_method(lambda t, y: t * y ** 0.5, 0, t[0], 0.1, 1)]

for i in range(1, len(t)):
    y1 += [euler_method(lambda t, y: t * y ** 0.5, t[i - 1], t[i], 0.1, y1[-1])]

y2 = (t ** 2 + 4) ** 2 / 16

plt.plot(t, y1, label='estimated', marker='.')
plt.plot(t, y2, label='calculated', marker='.')
plt.grid(linestyle='--')

plt.title("Euler method")
plt.xlabel('t')
plt.ylabel('y')

plt.legend()

plt.show()

for _t, _y1, _y2 in zip(t, y1, y2):
    print(f"t = {_t}:\n\tEstimated: {_y1}\n\tCalculated: {_y2}\n")

```

##### Implicit Euler method testing 
Function: $y'(t) = t\sqrt{y(t)}$ \
Initials: $t_0=0, \ y_0=y(t_0)=y(0)=1$ \
Step: $\tau=0.1$

#### Реализовать неявный метод Эйлера


```python
def implicit_euler_method(f, t0, tn, tau, y0):
    
    eps = tau / 10000
    
    while t0 + tau < tn and abs(tn - t0) > eps:
        
        t0 += tau
        y = Symbol('y')
        
        y0 = solve(y - tau * f(t0, y) - y0, y)[0]
        
    return y0
    
```


```python
t = np.arange(0, 11, 1, int)
y1 = [implicit_euler_method(lambda t, y: t * y ** 0.5, 0, t[0], 0.1, 1)]

for i in range(1, len(t)):
    y1 += [implicit_euler_method(lambda t, y: t * y ** 0.5, t[i - 1], t[i], 0.1, y1[-1])]

y2 = (t ** 2 + 4) ** 2 / 16

plt.plot(t, y1, label='estimated', marker='.')
plt.plot(t, y2, label='calculated', marker='.')
plt.grid(linestyle='--')

plt.title("Implicit Euler method")
plt.xlabel('t')
plt.ylabel('y')

plt.legend()

plt.show()

for _t, _y1, _y2 in zip(t, y1, y2):
    print(f"t = {_t}:\n\tEstimated: {_y1}\n\tCalculated: {_y2}\n")

```

#### Реализовать метод Рунге-Кутты 4 порядка


```python
def runge_kutta(f, t0, tn, tau, y0):
    
    eps = tau / 10000
    
    while t0 < tn and (tn - t0) > eps:
        
        k1 = f(t0, y0)
        k2 = f(t0 + tau / 2, y0 + tau * k1 / 2)
        k3 = f(t0 + tau / 2, y0 + tau * k2 / 2)
        k4 = f(t0 + tau, y0 + tau * k3)
        
        y0 += tau / 6 * (k1 + 2 * k2 + 2 * k3 + k4)
        t0 += tau
        
    return y0
```


```python
t = np.arange(0, 11, 1, int)
y1 = [runge_kutta(lambda t, y: t * y ** 0.5, 0, t[0], 0.1, 1)]

for i in range(1, len(t)):
    
    y1 += [runge_kutta(lambda t, y: t * y ** 0.5, t[i - 1], t[i], 0.1, y1[-1])]

y2 = (t ** 2 + 4) ** 2 / 16

plt.plot(t, y1, label='estimated', marker='.')
plt.plot(t, y2, label='calculated', marker='.')
plt.grid(linestyle='--')

plt.title("Runge-Kutta method")
plt.xlabel('t')
plt.ylabel('y')

plt.legend()

plt.show()

for _t, _y1, _y2 in zip(t, y1, y2):
    print(f"t = {_t}:\n\tEstimated: {_y1}\n\tCalculated: {_y2}\n")

```


```python

```

5e8eecfaf78cfc8197f04d22b9f9a5749eea6328
ipynb
Jupyter Notebook
Damarad_Viktor/differencial_systems.ipynb
droidroot1995/DAFE_Python_914
0de65a84ab7f4c8f24b83a5747f71f52d57ecc20
Unlicense
Damarad_Viktor/differencial_systems.ipynb
droidroot1995/DAFE_Python_914
0de65a84ab7f4c8f24b83a5747f71f52d57ecc20
Unlicense
2021-05-08T22:02:59.000Z
2021-05-13T22:44:27.000Z
Damarad_Viktor/differencial_systems.ipynb
droidroot1995/DAFE_Python_914
0de65a84ab7f4c8f24b83a5747f71f52d57ecc20
Unlicense
2021-02-13T07:32:10.000Z
2021-05-15T09:09:08.000Z
Qwen/Qwen-72B
1. YES
2. YES