In this lecture, you will learn to sketch free-body and kinetic diagrams of a simple pendulum. Furthermore, you will learn to develop the equation of motion describing the dynamics of the pendulum. Finally, you will learn how to develop a MATLAB code that solved the equations of motion. A YouTube video accompanying this post is given below.
Figure 1 below shows a sketch of a simple pendulum. A simple pendulum consists of a bob of a mass attached to a cord of length that can freely oscillate in the gravitational field. The simple pendulum is a simplified model of a number of real-life systems. More about this will be explained in future lectures.
The free-body diagrams and kinetic diagrams of the bob are shown in Fig.2 below (Sketch the free body diagram of the bob by yourself).
From the second Newton law we have:
(1)
where
(2)
Now, the natural coordinate system for projecting the equation (1) is formed by the normal and tangential components of the acceleration vector that are shown in Fig. 2.
By projecting the equation on the tangential unit vector (tangential axis), we obtain
(3)
From the last equation, we obtain:
(4)
Since the velocity is given by
(5)
The tangential acceleration is given by
(6)
By substituting the last equation in (5), and by didividing the resulting equation by , we obtain the final equation of motion:
(7)
This is a nonlinear second order differential equation. It is nonlinear since there is a nonlinear function in the equation. It is of the second order since, the maximum derivative is of the second order.
To numerically solve this equation using MATLAB, we will transform this equation in the state-space form. First, we need to assign the state-space variables:
(8)
From the last equation and the equation (7), we have:
(9)
and
(10)
The equations (9) and (9) can be compactly written as a single vector equation:
(11)
The vector equation (11) is a state-space form of the equation of motion (7). So, we have written the second order differential equation as a system of two first order differential equation. Now, that we have a state-space model of our original equation of motion, we can easly solve it using MATLAB.
The first step is to define the state-space model in a separate MATLAB function. The code is given below.
function dx=dynamics_pendulum(t,x)
mass=1; % define the mass of the bob
l=0.5; % define the length of the cord
g=9.81; % gravitational acceleration
% define the state-space model
dx=[x(2,1); -(g/l)*sin(x(1,1))];
end
The arguments of this function are time and vector . The entries of this vector, denoted by x(1,1) and x(2,1) correspond to the state-space variables and defined above. The state-space model is defined on the code line 7. This code line corresponds to the equation (11). The variable dx corresponds to the right-hand-side of this equation. This function should be saved in the file “dynamics_pendulum.m”, and the folder containing this function should be added to the MATLAB path.
Finally, from the next MATLAB script, we can execute the following code
% time vector
time_step=0.05
time_vector=[0:time_step:10];
% initial condition
x0=[0;1]
[time_vector2,solution]=ode45(@dynamics_pendulum,time_vector,x0);
plot(time_vector2,solution(:,1),'r')
grid
hold on
plot(time_vector2,solution(:,2),'k')
The numerical solution approximates the exact solution of the system at the discrete-time steps defined in the vector “time_vector” defined on the line 3. The variable “time_step” defines the discretization time step. In our case, we will approximate the solution from the time instant seconds until time instant seconds. The code line 5 defines the initial condition, in our case and . Finally, the code line 7 calls the MATLAB ode45() solver. This is a built-in MATLAB function for solving ordinary differential equations. The first argument of this function tells to ode45() solver the name of the file in which the state-space model is defined. In our case, it is the file “dynamics_pendulum.m”. The symbol @ means “at”. The second argument defines the time vector containing discrete time instant for which the solution will be approximated and the third parameter is the initial condition. The ode45() function returns two variables: “time_vector2” containing time instants (that is in our case equal to “time_vector”) and the solution matrix, represented by the variable “solution”. The first column of this matrix corresponds to the solution while the second column corresponds to the solution . Finally, on lines 10-13, we plot the solution. The results are given in Figure 3 below.