SIMULATION OF 2ND ORDER SIMPLE PENDULUM EQUATION
SIMULATION OF 2ND ORDER SIMPLE PENDULUM EQUATION
AIM:-
1.Simulate the anguler velocity and anguler displacement of the simple pendulum,by conversion of 2nd order of ode equaition into 1 st order with hep of matlab.
2.Create a animation video of simple pendulum by using movie commond with the result of 2nd order equation.
OBJECTIVES:-
1.Plot the result of anguler velocity and anguler displacement by solving th 2nd order ODE equation.
2.With the results of 2 nd order ODE equation ,create one animation video of simple pendulum.
THEORY:-
A pendulum is a weight suspended from a pivot so that it can swing freely. When a pendulum is displaced sideways from its resting, equilibrium position, it is subject to a restoring force due to gravity that will accelerate it back toward the equilibrium position.
When released, the restoring force acting on the pendulum's mass causes it to oscillate about the equilibrium position, swinging back and forth. The time for one complete cycle, a left swing and a right swing, is called the period.
The period depends on the length of the pendulum and also to a slight degree on the amplitude, the width of the pendulum's swing.
FIGURE:-
2ND ORDER DIFFERENTIAL EQUATION:
`(d^2theta)/dt^2+(b/m).(d(theta))/dt+(g/l).sin(theta)=0`
here assumed values are
b=damping co-efficient=0.05
m=mass of bob=1kg
g=acceleration due to gravity=9.81`m/s^2`
l=length=1m
here we assume,
`theta=theta1`then,
`(d.theta)/dt=(d.theta1)/dt=theta2`
`(d^2.theta)/dt^2=d/dt[(d.theta)/dt]=(d.theta 2)/dt`
By substituting these in 2nd order ODEequation,we get
`(d.theta2)/dt=b/m.theta2+g/l.sin (theta1)=0`
In order to solve this original 2nd order ODE equation,we have to break dowm this equation into series of 1 st order ODE's
1 st ODE equation=`(d.theta)/dt=(theta2)`
2 nd ODE equation=`(d.theta2)/dt=-b/m.theta2-g/l.sin(theta1)`
PROGRAM TO SIMULAT THE ANGULER DISPLACEMENT&ANGULER VELOCITY OF PENDULUM:-
clc
clear all
close all
b=0.05;
g=9.81;
l=1
m=0.1;
%intial condition
theta_0=[0;3];
%time points
t_span=linspace(0,10,500)
figure(1)
%solve ode
[t,result]=ode45(@(t,theta) ode_fn(t,theta,b,g,l,m),t_span,theta_0);
plot(t,result(:,1))
hold on
plot(t,result(:,2))
ylabel('plot')
xlabel('time')
RESULT:1
FUNCTION:-
function[dtheta_dt]=ode_fn(t,theta,b,g,l,m)
theta1=theta(1)
theta2=theta(2)
dtheta_dt=theta2;
dtheta2_dt=-(b/m)*theta2-(g/l)*sin(theta1);
dtheta_dt=[dtheta_dt;dtheta2_dt]
end
MAIN PROGRAM:-
clc
clear all
close all
b=0.05;
g=9.81;
l=1
m=0.1;
%intial condition
theta_0=[0;3];
%time points
t_span=linspace(0,10,500)
figure(1)
%solve ode
[t,result]=ode45(@(t,theta) ode_fn(t,theta,b,g,l,m),t_span,theta_0);
plot(t,result(:,1))
hold on
plot(t,result(:,2))
ylabel('plot')
xlabel('time')
%animation
theta=result(:,1);
ct=1;
for i=1:length(theta);
THETA=theta(i);
x0=0;
y0=0;
x1=1*sin(THETA);
y1=-1*cos(THETA);
figure(2)
plot([-0.5 0.5],[0 0],'linewidth',10,'color','g');
hold on
plot([x0 x1],[y0 y1],'linewidth',3,'color','b');
hold on
plot(x1,y1,'marker','.','markersize',50) ;
hold on
axis([-1 1 -1.5 0.5]);
hold off
pause(0.01);
M(ct)=getframe(gcf)
ct=ct+1;
end
movie(M)
videofile=videowriter('simple pendulum.avi','uncompressed avi')
open(videofile)
writeVideo(videofile,M)
close(videofile)
EXPLINATION:-
1.Given the inputs require.
2.By using the ode45 commond ,created one function and named it as ode_fn becase of the function got the unknow values (t & result)
3.Ploted the results as per require ment and named to the labels .
4.Created the simple pendulem.
4.By using the ct=1 ; ct=ct=1 and created animation movie.
ERRORS OCCURED:-
Found Video not saved,and found some correction in the word of video writer.
CORRECTION MADE:-
VideoWriter (v & w writen wrong so corrected those are as capital letters).
FINAL RESULT:-
1.Simulated the anguler velocity and anguler displacement of the simple pendulum,by conversion of 2nd order of ode equaition into 1 st order with hep of matlab.
2.Created an animation video of simple pendulum by using movie commond with the result of 2nd order equation.