Week 3 - Solving second order ODEs
MOTION OF A SIMPLE PENDULUM WITH DAMPING BY ODE
AIM :
A program in matlab that solves the ODE represents the equation of motion of a simple pendulum with damping.
EXPLANATION :
A simple pendulum consists of a mass m hanging from a string of length L and fixed at a pivot point P. When displaced to an initial angle and released, the pendulum will swing back and forth with periodic motion.
The program was done by using this equation,
At first convert this formula into matrix form, Also converting into two first order ODE,
Given inputs :
length of string (L)=1 metre,
Mass (m)=1 kg,
Damping coeffocient (b)=0.05.
Acceleration due to gravity (g)=9.81 m/s2.
the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0.
The program to calculate above equation,
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)*sin(theta1);
dtheta_dt = [dtheta1_dt; dtheta2_dt];
end
The above program which solves the equation which is in matrix form.
the program was solved as per the RK method by using above equation,
ode45 was the code here to solve differential equation.
% Motion_of_pendulum_using_ODE_function
clear all
close all
clc
b = 0.05;
g = 9.81;
l = 1;
m = 1;
% initial_condition
theta_0 = [0;3]
% time_points
t_span = linspace(0,20,100)
% slove_ODE
[t,result] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);
figure (1)
plot(t,result(:,1))
hold on
plot(t,result(:,2))
axis([0 20 -4 4])
title('pendulum displacement and velocity')
xlabel('time')
ylabel('displacement and velocity')
ct=1;
for i=1:length(result(:,1))
x0 = 0
y0 = 0
x1 = -l*sin(result(i,1))
y1 = -l*cos(result(i,1))
figure (2)
plot([-1,1],[0,0],'linewidth',3,'color','g')
line([x0,x1],[y0,y1],'linewidth',3,'color','b')
hold on
plot(x1,y1,'o','markersize',20,'markerfacecolor','r');
axis([-2 2 -3 1]);
pause(0.01);
hold off
V(ct)=getframe(gcf);
ct=ct+1;
end
movie(V)
videofile=VideoWriter('pendulum.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,V)
close(videofile)
Result 1 :
Result 2 :
The animation as shown in the youtube link = https://www.youtube.com/watch?v=eyqMrpLSCYo
CONCLUSION :
Hence the program in matlab to solves the ODE represents the equation of motion of a simple pendulum with damping is concluded sucessfully.