Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Jupyter notebook pendulo.ipynb

78 views
Kernel: Python 2
from numpy import * from scipy import * from scipy.integrate import * from pylab import * %matplotlib inline
θ¨+glsinθ=0\ddot \theta + \sqrt{\frac{g}{l}} \sin \theta = 0

Convertiendo a un sistema de ecuaciones: θ˙=vθ\dot \theta = v_{\theta} v˙θ=glsinθ\dot v_{\theta}= -\sqrt{\frac{g}{l}} \sin \theta Mis variables sin la pareja ordenada (θ,vθ)(\theta , v_{\theta})

def pendulo(vec_r, t, g=9.8 , l=1.0): return [ vec_r[1], -sqrt(g/l)*sin(vec_r[0])]
pendulo([0, pi/2, pi], g=9.8, l=1.0)
[1.5707963267948966, -0.0]
tiempo= linspace(0,2*pi) cond_ini = [0, 1] solucion = odeint(pendulo, cond_ini, tiempo) plot(tiempo,solucion[:,0], tiempo,solucion[:,1] )
[<matplotlib.lines.Line2D at 0x106e78e50>, <matplotlib.lines.Line2D at 0x106e85110>]
Image in a Jupyter notebook
plot(solucion[:,0],solucion[:,1])
[<matplotlib.lines.Line2D at 0x107090950>]
Image in a Jupyter notebook
print solucion[:,0]
[ 0. 0.19198671 0.38069649 0.56079901 0.72594114 0.86957723 0.9855581 1.06848641 1.11386789 1.11814592 1.07874473 0.99425063 0.86482821 0.69289004 0.48389662 0.24697693 -0.00506707 -0.25670056 -0.49144808 -0.69394468 -0.85149477 -0.954732 -0.99752147 -0.97659837 -0.89146166 -0.74483559 -0.5436674 -0.30018374 -0.03213716 0.23856288 0.4888144 0.697741 0.84908629 0.93194348 0.94033381 0.87267343 0.73194428 0.52673988 0.27253553 -0.00815899 -0.28797839 -0.53900755 -0.73729008 -0.86547347 -0.9131573 -0.87613396 -0.75603428 -0.56112506 -0.30777362 -0.02092843]
tiempo = linspace(0,5*pi,200) N=50 for i in range(N): cond_ini=[rand(),rand()] solucion =odeint(pendulo, cond_ini,tiempo) plot(solucion[:,0],solucion[:,1])
Image in a Jupyter notebook