Week 3 - Solving second order ODEs
AIM:-To simulate the motion of Pendulum and show its transicent behaviour
THEORY:- A simple Pendulum consist of a mass m suspended by a string of length l,The angle it makes with the vertical varies with time as a sine or cosine
OBJECTIVES:-
- To Simulate the motion of the Pendulum
- To show transient behaviour of Pendulum
Governing Equation and Inputs
`(d^2theta)/(dt^2)+(b)/(m)(d theta)/(dt)+(g)/(l)sin theta=0`
L=1 metre , m-1kg, b(damping cofficient)=0.05, g=9.81m/s2
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)*sin(theta1); dtheta_dt=[dtheta1_dt; dtheta2_dt] end
MAIN PROGRAM
clear all
close all
clc
%Input Parameters
b=0.05; %Damping COfficient
m=1; %mass
l=1; %Length
g=9.81; %Gravity
%Initial position and Velocity
theta_0=[0;3];
%Time points
t_span=linspace(0,20,200);
%Solve ODE
[t,results]=ode45(@(t,theta) ode_func(t,theta,b,g,l,m), t_span, theta_0);
figure(1)
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel('Plot')
xlabel('Time')
legend('Displacement','Velocity')
title('Transient Behaviour')
%For pendulum
ct=1;
for i=1:length(t_span)
Result=results(i);
%starting coordinates
x0=0;
y0=0;
%End coordinates
x1=l*sind(Result);
y1=-l*cosd(Result);
%Pliot thread
figure(2)
plot([x0 x1],[y0 y1],'linewidth',1,'color','r')
hold on
%Represent the ceiling
plot([1 -1],[0 0],'linewidth',5,'color','y')
%Plot a bob
plot(x1,y1,'marker','o','markersize',15,'markerfacecolor','b')
axis([-1.5 1.5 -1.5 1.5])
pause(0.00005)
M(ct)=getframe(gcf);
hold off
ct=ct+1;
end
movie(M)
videofile=VideoWriter('Pendulum','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)EXPLATION
Step 1- Specify all the input parameters
Step2 - provide initial position and velocity
Step 3 - Provide time span using linspace command
Step 4 - use ode45 command to get the results
Step 5- plot velocity vs time and displacement vs time graph
Step 6-Then the position of the bob can be find from sine and cosine
Step 7-Create ceiling and bob
Step 8-Use movie command to make the video
RESULT-TRANSIENT BEHAVIOUR OF PENDULUM
Simulation Video-https://youtu.be/2vWbNJgavLc
CONCLUSION- Successfully simulated the motion of pendulum and showed Transient behaviour of Pendulum