SharedJupyterWidgets / ODE-Interactive.ipynbOpen in CoCalc

ODE system - interactively¶

System of differential equations
$\dfrac{y}{f}e^{-kx}-1 =\dfrac{dy}{dx} \\ \hspace{0.5 cm} -\dfrac{1}{2\sqrt{y}} =\dfrac{dt}{dx}$

Initial conditions
$y(1)=0, t(1)=0$

# python library
import ipywidgets as widgets
from IPython.display import display
import matplotlib.pyplot as p
import numpy as np
from scipy.integrate import odeint
import math

%matplotlib nbagg

# ODE system
def F(z,x,f=1/260.0,k=5.0):
value = [0,0]
value[0] = z[0]/f*math.exp(-k*x)-1
value[1] = -1/2*1/math.sqrt(z[0])
return value

# data x
xp = 1; xk = 0; dx =-0.0005
xh = np.arange(xp, xk+dx,dx)
ics = (1e-15,0)

# graph
p.figure(figsize=(8, 5),dpi=100)
ax = p.subplot(111)
p.title("Energy vs. height ",fontsize=15)

def graf(f,k):
ax.clear()
z = odeint(F,ics,xh,args=(f/10,k))
Kh = z[:,0]
th = z[:,1]
p.plot(th,Kh)
ax.set_ylim(0, 0.5)
ax.set_xlim(0, 3)
p.grid(c='0.7', lw = 0.5)
p.axhline(0, color='black',lw=0.75)
p.axvline(0, color='black',lw=0.75)
p.show()

#widget
f = widgets.FloatSlider(min=0.01, max=0.1, step=0.01, value=0.004, description='f(10^(-1):')
k = widgets.FloatSlider(min=0, max=5, step=0.05, value=5, description='k:')

widgets.interactive(graf, f=f, k=k)

WARNING: Some output was deleted.