Demo entry 6763124

task

   

Submitted by anonymous on Oct 19, 2018 at 14:26
Language: Python. Code size: 657 Bytes.

import numpy as np
import matplotlib.pyplot as plt
from scipy import integrate
from pylab import * # for plotting commands

g=9.8
R=5.
#Direct numerical solution:

def rlc(A,t):
    p,w=A
    res=array([w,-g/R*np.sin(p)])
    return res
    
time = linspace(0.0,20,10001)
phi0=20.
p,w = integrate.odeint(rlc,[phi0/180.*np.pi,0],time).T

#Now, solution with approximation:
f=sqrt(g/R)
pa=phi0/180.*np.pi*cos(f*time)

#plt.plot(time,w,'r-',linewidth=2,label='Omega')
plt.plot(time,p,'b-',linewidth=2,label='Phi_NUM')
plt.plot(time,pa,'r-',linewidth=2,label='Phi_APP')
plt.xlabel('time')
plt.ylabel('phi(t)')
plt.legend()
plt.show()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).