Reputation: 3
I have copy-and-pasted the Lotka-Volterra example for Scipy's solve_ivp
function from the documentation here, but I get the error
lotkavolterra() missing 4 required positional arguments: 'a', 'b', 'c', and 'd'
It seems to me that the arguments aren't being passed to lotkavolterra
despite it "example of a system with additional parameters". The code is below.
from scipy.integrate import solve_ivp
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), dense_output=True)
print(sol)
How do I resolve my issue?
Upvotes: 0
Views: 433
Reputation: 7157
If your version of solve_ivp doesn't provide the args
argument, you can use a lambda function:
sol = solve_ivp(lambda t, z: lotkavolterra(t, z, 1.5, 1, 3, 1), [0, 15], [10, 5], dense_output=True)
However, it's highly recommended to update your scipy version, like Warren already hinted in the comments.
Upvotes: 1