Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import pandas as pd
- import matplotlib.pyplot as plt
- def f(x, p):
- return (1-x) * x - p*x
- def euler_method(function, x_0, t_0, tf, dt, p):
- n = int((tf - t_0) / dt)
- x = [x_0] * (n+1)
- t = [t_0 + i*dt for i in range(n+1)]
- for i in range(n):
- x[i+1] = x[i] + function(x[i], p) * dt
- return t, x
- def grafik0():
- for p in P:
- t, x = euler_method(f, 0.1, 0, 10, 0.01, p)
- plt.plot(t, x, label=f'p={p}')
- plt.title(f"s(t)")
- plt.xlabel("t")
- plt.ylabel("x")
- plt.grid()
- plt.legend()
- plt.show()
- P = [0.3, 0.5, 0.8]
- print(f'df/dx = (1 - x)x - p * x\n')
- grafik0()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement