Tema 4
Tema 4
- It is desired to analyze the angular motion ( t ) of a disk which oscillates in a circular trajectory as
shown in the figure. Consider the following characteristics for the system: r: 10 cm, R: 60 cm, M: 2.45
kg, and J: 122.5 kg cm2. It is desired to determine the period of oscillation with different values of
amplitude of oscillation. Implement the 4th order Runge-Kutta method to numerically solve the
following nonlinear 2nd order ordinary differential equation which represents the motion of the disk:
− 1 )2 + Mg ( R − r )sen = 0
R
M ( R − r )2 + J (
r
You can use any language of computer programming (Python, Visual Fortran or MatLab). You
have to include the source code of your program with enough comments to facilitate the evaluation, as
the appendix of your report.
To analyze your results, plot the angular position of the disk vs time, starting with different
initial positions.
Due: Friday Oct 13th. You must report the number of hours employed for this homework
jrml/23
import numpy as np
import matplotlib.pyplot as plt
import math
#we must to def the function that in we will use in the Rk4th, with its
variables
def funcion(value):
g=9.81
r=0.1
R=0.6
M=2.45
J=0.01225
theta=-(M*g*math.sin(value))/((R-r)*(M+(J/(math.pow(r,2)))))
return theta
#we must to define the list where can be stored the initial conditions, an in
which can be named the function of Rk4th
def cini(time, w1, w2):
listw1 = [w1]
listw2 = [w2]
for i in range(len(time) - 1):
w1i, w2i = RK4(listw1[i], listw2[i])
listw1.append(w1i)
listw2.append(w2i)
return time, np.array(listw1)
def period(list1, list2):
Amp_max=max(list1[:250])
Amp_min=min(list1[:250])
periodo=2*abs(list2[list1.index(Amp_max)]-list2[list1.index(Amp_min)])
return periodo
#here we can develop the code of the Rk4th method, in which can be returned 2
values of w
def RK4(w1, w2):
h=0.01
k11=h*w2
k12=h*funcion(w1)
k21=h*(w2+k12/2)
k22=h*funcion(w1+k11/2)
k31=h*(w2+k22/2)
k32=h*funcion(w1+k21/2)
k41=h*(w2+k32)
k42=h*funcion(w1+k31)
w11=w1+(1/6)*(k11+2*k21+2*k31+k41)
w22=w2+(1/6)*(k12+2*k22+2*k32+k42)
return w11, w22
#here can be created an imputs where can be inserted the information about
the initial conditions, in fractions of pi
time = np.arange(0, 10, 0.01)
cond1=float(input('First initial condition: '))
cond2=float(input('Second initial condition: '))
cond3=float(input('Third initial condition: '))
condin=[cond1*math.pi, cond2*math.pi, cond3*math.pi]
w2=[0, 0, 0]
wi11=[]
lista_periodos=[]
#here can be defined the way in which the information will be presented ,
from the data management to the graphic representation
def graph_results(x, results):
for i in range(len(results)):
plt.plot(x,np.array(results[i]))
plt.xlabel('T [s]', fontsize=10)
plt.ylabel('Angular position [rad]', fontsize=10)
plt.title('Angular position of the disk vs T\n', fontsize=10)
plt.legend(((cond1,'pi','Period:',lista_periodos[0]),
(cond2,'pi','Period:',lista_periodos[1]),
(cond3,'pi','Period:',lista_periodos[2])), loc='lower center')
plt.show()
for i in range(len(condin)):
lt, listw1=cini(time, condin[i], w2[i])
wi11.append(listw1)
x=period(list(listw1), list(time))
lista_periodos.append(x)
graf=graph_results(lt, wi11)
print(lista_periodos)
This analysis help us to obtain a better approximation to the analysis, based on the calculation of 4
coefficients, which its transform in the average of 2 points, for this analysis a code were developed to
represent the oscillation of a disc in which the initial point can be changed in pi fractions, can be observed
that if the angle of the initial point are higher, the amplitude of the oscillation increases and the period,
decreases, this can be traduced in higher frequency of oscillations, it can be corroborated running the
code and varying the value of the angle from lowest to higher values, in this case particularly, the values
where 0.2 pi , 0.5 pi, and 0.8 pi, which give us periods of 1.78s , 2.06s and 2.88 s respectively.
Time: 4h