I am studying python for what concerns ode numerical integration, in particular I found the scipy.integrate function solve_ipv
. I tried the example shown in the scipy.integrate.solve_ipv page but there is a clear mistake in the code related to the Lotka Volterra example:
def lotkavolterra(t, z, a, b, c, d):
x, y = z
return [a*x - b*x*y, -c*y + d*x*y]
sol = solve_ivp(lotkavolterra, [0, 15], [10, 5], args=(1.5, 1, 3, 1))
t = np.linspace(0, 15, 300)
z = sol.sol(t)
import matplotlib.pyplot as plt
plt.plot(t, z.T)
plt.xlabel('t')
plt.legend(['x', 'y'], shadow=True)
plt.title('Lotka-Volterra System')
plt.show()
sol.sol(t)
has no meaning in this code. What should we write? Maybe a tuple z = sol.t, sol.y
?
It is also clear that len(sol.y[0])=57
and len(sol.y[1])=57
while t
has 300 elements. For this reason coupling their values for a plot can be a problem.
In the page there is also a plot of what we would obtain if the code run.
I don't think it's important but I am using python3.
EDIT: I did not insert dense_output=True
in solv_ipv()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…