Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

11th grade-all tasks

2151 views
Kernel: SageMath (stable)
import numpy as np from numpy import sin, cos from scipy.integrate import odeint from matplotlib import pyplot as plt # define the equations def equations(y0, t): theta, x = y0 f = [x, -(g/l) * sin(theta)] return f def plot_results(time, theta1, theta2): plt.plot(time, theta1[:,0]) plt.plot(time, theta2) s = '(Initial Angle = ' + str(initial_angle) + ' degrees)' plt.title('Metotalet: ' + s) plt.xlabel('time (s)') plt.ylabel('angle (rad)') plt.grid(True) plt.legend(['nonlinear', 'linear']) plt.show() # parameters g = 9.81 l = 1.0 E_lst=[] E=0 m=10 time = np.arange(0, 12.0, 0.025) #def enegry(thethadot, theta): # E=1/2*m*l**2*thetadot+m*g*l*(1-cos(theta)) # E_lst.append(E) # initial conditions initial_angle = input("choose an initial angle") theta0 = np.radians(initial_angle) x0 = np.radians(0.0) # find the solution to the nonlinear problem theta1 = odeint(equations, [theta0, x0], time) # find the solution to the linear problem w = np.sqrt(g/l) theta2 = [theta0 * cos(w*t) for t in time] #E_lst=[1/2*m*l**2*thetadot+m*g*l*(1-cos(theta))] # plot the results plot_results(time, theta1, theta2)
choose an initial angle
Image in a Jupyter notebook