I have a system of differential equations. The solutions depend on a parameter beta. I want to create a slider so I can change this parameter and display the changes of the solution curves directly in my plot. I almost got it I think, but I miss one piece.
My code
N = 1
#Initial conditions
I0 = 0.01
S0= N - I0
#System of diff. equations
def system(x, t, beta, gamma ):
I, S = x
dIdt = (beta/gamma*S-1)*I*gamma
dSdt = -(beta/gamma*S-1)*I*gamma
return dIdt, dSdt
#Parameters initial value
beta = 0.03
gamma = 0.017
#Initial cond. vector
y0 = I0, S0
#time grid
t = np.linspace(0, 1300, 1300)
# Solution
sol = odeint(system, y0, t, args=(beta, gamma))
################ Animations part ##################
fig, ax = plt.subplots()
plt.subplots_adjust(bottom = 0.25)
#solution curves for I and S
infected, = plt.plot(t, sol[:,0])
recovered, = plt.plot(t, sol[:,1])
axbeta = plt.axes([0.125, 0.1, 0.5, 0.05])
sliderbeta = Slider(axbeta, 'beta', 0, 1, valinit=beta)
def update_beta(val):
beta_value = sliderbeta.val
??????????????????????????????????????
fig.canvas.draw_idle()
sliderbeta.on_changed(update_beta)
plt.show()
I don't know how to acces my initial beta value and how to replace it by beta_value. I guess there is some line missing where I put the question marks.