Created
July 14, 2020 14:34
-
-
Save ruoyu0088/dc0f6c3c024b5ec502536c2f5d09348a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy import integrate | |
import numpy as np | |
def spring_sys(t, y, m, b, k, F): | |
x, v = y | |
dx = v | |
dv = (F - k * x - b * v) / m | |
return dx, dv | |
def run_sim(x0, v0, m, b, k, F, tend, n): | |
t = np.linspace(0, tend, n) | |
res = integrate.solve_ivp(spring_sys, (0, tend), (x0, v0), t_eval=t, args=(m, b, k, F)) | |
return hv.Curve((res.t, res.y[0])) | |
#run_sim(1, 0, 1, 0.1, 2, 0, 10, 100) | |
arguments = [arr.ravel() for arr in np.mgrid[0.5:2:2j, 0.1:1.0:3j, 0.5:3:3j, 0:1:3j]] | |
hm = hv.HoloMap(kdims=['m', 'b', 'k', 'F']) | |
for args in zip(*arguments): | |
hm[args] = run_sim(1.0, 0.0, *args, tend=10, n=50) | |
hm.overlay('k').layout(['m', 'b']).cols(3).opts( | |
hv.opts.NdOverlay(show_legend=True, legend_position='top', legend_cols=True), | |
hv.opts.Curve(show_grid=True) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment