Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
1931 views
ubuntu2004
Kernel: Python 3 (system-wide)

Coding for Atwood System Plan

There is no formal word limit but concise reports are preferred Guideline: approximately 1500 - 2000 words (excl. code) E.g. 10 paragraphs at 150 – 200 words per paragraph

para 1: problem motivation

para 2: problem details

para 3: finding a way into the problem

paras 4-6: methodological details

paras 7-8: results

paras 9-10: discussion and conclusions

Identify your key insight(s)

Consider your audience

Your report should be: Self-contained (your reader hasn’t read the brief!)

Coherent (easy to follow, well structured with clear ‘signposting’)

Don’t recount what you’ve learnt (unless it’s insightful)

NEXT WEEK:

Show a draft to your supervisor

Include major headings and working code

You don’t need to polish the text at this stage. Bullet points are fine!

They shouldn’t be concentrating on the detail.

Determine the scope of the problem they are solving,

the general components of the solution

And their (expected) key results (may not be clear yet)

What else do they need to communicate this?

Coding a simple pendulum

#Import recquired models import numpy as np import matplotlib.pyplot as plt #This allows us to code for ODEs from scipy.integrate import odeint #Setting values g = 9.81 L = 2 #Function- We convert the SHM ODE of a pendulum into 2 first order ODEs def model(y,t,g,L): #theta'(t) = omega(t) #omega'(t) = -(g/L)*(sin(theta(t))) theta, omega = y dydt = [omega, -(g/L)*(np.sin(theta))] return dydt #initial conditions #sets that at time=0, angular velocity is 3 radians per second y0 = [0-0.1,0.0] #time points t = np.linspace(0,10,101) #solve ODE sol = odeint(model, y0, t, args=(g,L)) #plotting results plt.plot(sol[:,0], sol[:, 1], 'b') plt.grid() plt.show()
Image in a Jupyter notebook
#Plots for change in theta (y axis) vs theta (x axis) plt.plot(sol[:,0], sol[:,1], 'r', label='special')
[<matplotlib.lines.Line2D at 0x7ff552c9b310>]
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt import math from scipy.integrate import odeint M=9 m=4 g=9.81 def Atwood(y,t,M,m,g): #theta'(t)=omega(t) #radius'(t)=Rho(t) #omega'(t)=(1/radius(t))(-g*sin(theta(t))-2(Rho(t)*omega(t)) #Rho'(t)=(1/(M+m))(m*radius(t)*(omega(t)^2)-M*g+m*g*cos(theta(t))) theta, omega, radius, Rho = y #dydt = [omega, (1/radius)*(-g*(np.sin(theta))-2*(Rho*omega)),Rho, (1/(M+m))*(m*radius*(omega^2)-M*g+m*g*(np.cos(theta)))] dydt = [omega, (1/radius)*(-g*(np.sin(theta))-2*(Rho*omega)), Rho, (1/(M+m))*(m*radius*(omega**2)-M*g+m*g*(np.cos(theta)))] return dydt y0 = [0-0.1,0.0,1,1] t = np.linspace(0,10,101) sul = odeint(Atwood, y0, t, args=(M,m,g)) plt.plot(t, sul[:, 0], 'b', label='theta') plt.plot(t, sul[:, 1], 'g', label='theta dot') plt.plot(t, sul[:, 2], 'y', label='r') plt.plot(t, sul[:, 3], 'p', label='r dot') plt.legend(loc='best') plt.grid() plt.show()
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt import math from scipy.integrate import odeint M=5 m=2 g=9.81 def Atwood(y,t,M,m,g): #theta'(t)=omega(t) #radius'(t)=Rho(t) #omega'(t)=(1/radius(t))(-g*sin(theta(t))-2(Rho(t)*omega(t)) #Rho'(t)=(1/(M+m))(m*radius(t)*(omega(t)^2)-M*g+m*g*cos(theta(t))) theta, omega, radius, Rho = y #dydt = [omega, (1/radius)*(-g*(np.sin(theta))-2*(Rho*omega)),Rho, (1/(M+m))*(m*radius*(omega^2)-M*g+m*g*(np.cos(theta)))] dydt = [omega, (1/radius)*(-g*(np.sin(theta))-2*(Rho*omega)), Rho, (1/(M+m))*(m*radius*(omega**2)-M*g+m*g*(np.cos(theta)))] return dydt #y0=[theta, change in theta, radius, change in radius] y0 = [0 ,2 ,1 ,1] #time points t = np.linspace(0,10,101) #Solving the ODE sul = odeint(Atwood, y0, t, args=(M,m,g)) plt.plot(sul[:,0], sul[:,1], 'r', label='theta (x) vs thata dot (y)') #Phase plot plt.legend(loc='best') plt.grid() plt.show()
Image in a Jupyter notebook
#Changing the masses
import numpy as np import matplotlib.pyplot as plt import math from scipy.integrate import odeint M=5 m=2 g=9.81 def Atwood(y,t,M,m,g): #theta'(t)=omega(t) #radius'(t)=Rho(t) #omega'(t)=(1/radius(t))(-g*sin(theta(t))-2(Rho(t)*omega(t)) #Rho'(t)=(1/(M+m))(m*radius(t)*(omega(t)^2)-M*g+m*g*cos(theta(t))) theta, omega, radius, Rho = y #dydt = [omega, (1/radius)*(-g*(np.sin(theta))-2*(Rho*omega)),Rho, (1/(M+m))*(m*radius*(omega^2)-M*g+m*g*(np.cos(theta)))] dydt = [omega, (1/radius)*(-g*(np.sin(theta))-2*(Rho*omega)), Rho, (1/(M+m))*(m*radius*(omega**2)-M*g+m*g*(np.cos(theta)))] return dydt #y0=[theta, change in theta, radius, change in radius] y0 = [0-0.1 ,2 ,1 ,1] #time points t = np.linspace(0,10,101) #Solving the ODE sul = odeint(Atwood, y0, t, args=(M,m,g)) plt.plot(sul[:,2], sul[:,3], 'r', label='radius (x) vs radius dot (y)') #Phase plot plt.legend(loc='best') plt.grid() plt.show()
Image in a Jupyter notebook
#Import recquired models import numpy as np import matplotlib.pyplot as plt #This allows us to code for ODEs from scipy.integrate import odeint #Setting values g = 9.81 L = 2 #Function- We convert the SHM ODE of a pendulum into 2 first order ODEs def model(y,t,g,L): #theta'(t) = omega(t) #omega'(t) = -(g/L)*(sin(theta(t))) theta, omega = y dydt = [omega, -(g/L)*(np.sin(theta))] return dydt #initial conditions #sets that at time=0, angular velocity is 3 radians per second y0 = [0-0.1,0.0] #time points t = np.linspace(0,10,101) #solve ODE sol = odeint(model, y0, t, args=(g,L)) #plotting results plt.plot(sol[:,0], sol[:, 1], 'b') plt.grid() plt.show()
Image in a Jupyter notebook
import simplependulumcode
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt import math from scipy.integrate import odeint M=9 m=4 g=9.81 def Atwood(y,t,M,m,g): #theta'(t)=omega(t) #radius'(t)=Rho(t) #omega'(t)=(1/radius(t))(-g*sin(theta(t))-2(Rho(t)*omega(t)) #Rho'(t)=(1/(M+m))(m*radius(t)*(omega(t)^2)-M*g+m*g*cos(theta(t))) theta, omega, radius, Rho = y #dydt = [omega, (1/radius)*(-g*(np.sin(theta))-2*(Rho*omega)),Rho, (1/(M+m))*(m*radius*(omega^2)-M*g+m*g*(np.cos(theta)))] dydt = [omega, (1/radius)*(-g*(np.sin(theta))-2*(Rho*omega)), Rho, (1/(M+m))*(m*radius*(omega**2)-M*g+m*g*(np.cos(theta)))] return dydt y0 = [0-0.1,0.0,1,1] t = np.linspace(0,10,2000000) sul = odeint(Atwood, y0, t, args=(M,m,g)) plt.plot(t, sul[:, 2], 'y', label='r') plt.legend(loc='best') plt.grid() plt.show() #
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint g = 9.81 L = 2 def model(y,t,g,L): theta, omega = y dydt = [omega, -(g/L)*(np.sin(theta))] return dydt y0 = [0-0.1,0.0] t = np.linspace(0,10,101) sol = odeint(model, y0, t, args=(g,L)) plt.plot(t, sol[:, 0], 'b') plt.grid() plt.show()
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint g = 9.81 L = 2 def model(y,t,g,L): theta, omega = y dydt = [omega, -(g/L)*(np.sin(theta))] return dydt y0 = [0-0.1,0.0] t = np.linspace(0,10,101) sol = odeint(model, y0, t, args=(g,L)) plt.plot(t, sol[:, 1], 'b') plt.legend(loc='best') plt.title('Fig 3.2 - time/angular velocity plot of simple pendulum') plt.ylabel('Angular velocity') plt.xlabel('Time') plt.grid() plt.show() plt.plot(t, sol[:, 0], 'b') plt.legend(loc='best') plt.title('Fig 3.3 - time/angular displacement plot of simple pendulum') plt.ylabel('Angular displacement') plt.xlabel('Time') plt.grid() plt.show()
No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument.
Image in a Jupyter notebook
No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument.
Image in a Jupyter notebook