SIMULATION OFMOTION OF SIMPLE PENDULUM
AIM: MATLAB Program which will simulate the motion of pendulum by solving the given ODE (Ordinary Differential Equation).
THEORY:
A Pendulum is a body suspended from a fixed support so that it swings freely back and forth under the influence of gravity.
The way the pendulum moves depends on the Newtons second law. When this law is written down, we get a second order Ordinary Differential Equation that describes the position of the "ball" w.r.t time.
The differential equation which represents the motion of a simple pendulum is
`(d^2 θ)/(dt^2) +b/m ((dθ)/dt)+ g/l sinθ= 0`
GOVERNING EQUATION:
`(d^2 θ)/dt^2 +b/m ((dθ)/dt)+ g/l sinθ= 0`
where,
b is the damping co-efficient,
m is the mass of the ball,
g is acceleration due to gravity,
l is the length of the pendulum,
and θ is the angular displacement.
INPUT VALUES:
l = 1 metre
m = 1 kg
b = 0.05
g = 9.81 m/s^2
angular displacement=0 and angular velocity=3 rad/sec at time t=0
and simulation time = 0 – 20 sec.
OBJECTIVE:
- Program to solve the given ODE which represents the equation of motion of a pendulum with damping.
- Simulate the motion of pendulum for given time, angular displacement and angular velocity.
FUNCTION PROGRAM:
function [dtheta_dt] = ode_func(t,theta,b,g,l, m)
theta1 = theta(1);
theta2 = theta(2);
dtheta1_dt = theta2;
dtheta2_dt = -(b/m)*theta2 - (g/l)*sind(theta1);
dtheta_dt = [dtheta1_dt ; dtheta2_dt];
end
MAIN PROGRAM:
% Program to solve the ODE which represents the motion of simple pendulum with damping
clear all
close all
clc
% Damping co-efficient
b = 0.05;
% Acceleration due to gravity (m/s^2)
g = 9.81;
% Length of pendulum (m)
l = 1;
% Mass of ball (kg)
m = 1;
%Intial condtition
theta_0 = [0;30];
% Time points
t_span = linspace(0,20,100);
% Solving ODE
[t, results] = ode45(@(t, theta) ode_func(t, theta, b, g, l, m),t_span, theta_0);
% Plot angular displacement, angular velocity vs time
figure(1)
plot(t, results(:,1))
hold on
plot(t, results(:,2))
title('Angular displacement and angular velocity wrt to time' )
xlabel('Time')
ylabel('Plots')
legend('Displacement','Velocity')
figure(2)
% Loop for animation
ct = 1;
for i = 1:length(t_span)
RESULTS = results(i);
% Coordinates
x0 = 0;
y0 = 0;
x1 = l*sind(RESULTS);
y1 = -l*cosd(RESULTS);
%Plotting
% Plot reprsenting the horizontal fixed support
plot ([-0.5 0.5],[0,0],'linewidth',3,'color','g')
hold on
% Plot representing the massless thread
plot([x0 x1],[y0 y1],'linewidth',2,'color','b')
% Plot representing the ball
plot(x1,y1,'o','markers',15,'markerfacecolor','r')
grid on
title('Simple Pendulum Motion')
legend('Fixed support','thread','ball')
xlabel('X axis')
ylabel('Y axis')
axis([-2.5 2.5 -2.5 2.5])
hold off
M(ct) = getframe(gcf);
ct = ct+1;
end
% Creating movie for simple pendulum
movie(M)
videofile = VideoWriter('ode_main_vid.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
OUTPUT:
Plot for angular displacement , angular velocity v/s time
EXPALNATION OF THE CODE:
-
A function program is created using a proper function which cover the ODE broken into first order.
-
Then Main program is solved using a inbuilt solver Ode45
CONCLUSION:
We have established and created the simulation of motion of simple pendulum by solving the given second order ODE. And , animation is also created for the motion of pendulum.
REFERENCES:
https://www.mathworks.com/help/matlab/ref/ode45.html
https://en.wikipedia.org/wiki/Pendulum_(mathematics)