Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Path: pub / 1-101 / 42.sagews
Views: 168738
Image: ubuntu2004
import scipy.integrate import numpy as N from sage.ext.fast_eval import fast_float y,yp,t=var("y,yp,t")
In the interact below, the black line represents the forcing function and the blue line represents $u(t)$, which gives the position of the mass.
@interact def plot_de( #mgk = input_grid(1,3,default=[1,0.125,1],label="m,g,k",width=10), initial = input_grid(1,2,default=[0,0],label="u(0), u'(0)",width=10), m = slider(1,10),g=(0,10),k=(1,10), forcing=input_box(3*cos(2*t),type=SR), #max_t=slider(0,100,default=10), #num_points = slider(100,1000,default=500) ): # m,g,k = mgk[0] max_t = 40 num_points=500 xmin,xmax = 0,max_t u0, u0p = initial[0] fast_deriv = fast_float(-g/m*yp-k/m*y+forcing(t), "y","yp","t") def f(Y,t): y,yp = Y return yp, fast_deriv(y,yp,t) points = N.linspace(float(xmin),xmax,num_points) lp = list_plot(zip(points,[i[0] for i in scipy.integrate.odeint(f,[u0,u0p],points)]), plotjoined=True,thickness=2) force=plot(forcing,(t,xmin,xmax),rgbcolor=(0,0,0), thickness=0.5) show(lp+force)
u(0), u'(0) 
forcing 
[removed]
[removed]
[removed]
[removed]