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
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
(7)
This is a nonlinear second order differential equation. It is nonlinear since there is a nonlinear function
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
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