Advertisement
mirosh111000

Завдання 2

May 29th, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4.  
  5. def f(x, p):
  6.     return (1-x) * x - p*x
  7.  
  8. def euler_method(function, x_0, t_0, tf, dt, p):
  9.  
  10.     n = int((tf - t_0) / dt)
  11.     x = [x_0] * (n+1)
  12.     t = [t_0 + i*dt for i in range(n+1)]
  13.     for i in range(n):
  14.         x[i+1] = x[i] + function(x[i], p) * dt
  15.     return t, x
  16. def grafik0():
  17.     for p in P:
  18.         t, x = euler_method(f, 0.1, 0, 10, 0.01, p)
  19.         plt.plot(t, x, label=f'p={p}')
  20.     plt.title(f"s(t)")
  21.     plt.xlabel("t")
  22.     plt.ylabel("x")
  23.     plt.grid()
  24.     plt.legend()
  25.     plt.show()
  26.  
  27. P = [0.3, 0.5, 0.8]
  28. print(f'df/dx = (1 - x)x - p * x\n')
  29. grafik0()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement