Week 3 - Solving second order ODEs
MOTION OF SIMPLE PENDULAM (ODE45)
AIM :
- To write a program in Matlab to simulate transient behavior of a simple pendulam and cread its animation.
OBJECTIVE :
- To write a program that solves the following ODE.
- This ODE represents the equation of motion of a simple pendulum with damping.
GIVEN :
-
-
L=1 metre,
-
m=1 kg,
-
b=0.05.
-
g=9.81 m/s2.
-
Simulate the motion between 0-20 sec
-
Angular displacement=0
-
Angular velocity=3 rad/sec
- Time t=0.
-
Wher,
-
g = gravity in m/s2,
-
L = length of the pendulum in m,
-
m = mass of the ball in kg,
-
b=damping coefficient.
PROGRAM CODE :
% MOTION OF SIMPLE PENDULAM (ODE45)
clear allclose allclc
%Inputsl =1; %Length
%Time intervelt = linspace(0,20,150);
%Initial conditionx0 = [0 3];
%foe diffreantial eqaution using ode45 (matlab input funtion)[t x] = ode45('oed_func',t,x0);
%plotting for tracing of Angular displacement and Angular velocitysubplot(2,1,1)plot(t,x(:,1),'b','linewidth',3);xlabel('time t in sec')ylabel('Angular displacement');subplot(2,1,2)plot(t,x(:,2),'r','linewidth',3);xlabel('time t in sec')ylabel('Angular velocity');grid on;
%Animationx0 = 0;y0 = 0;ct = 1;for i =l:length(t) x1 = l*sin(x(i,1)); y1 = -l*cos(x(i,1));
figure(2) plot([-1 1],[0 0],'linewidth',5,'color','g'); axis([-2 2 -2 2]); line([x0 x1],[y0 y1],'linewidth',2,'color','b'); hold on; plot(x0,y0,'O','markersize',3,'markerfacecolor','y'); plot(x1,y1,'O','markersize',20,'markerfacecolor','r'); title('Damping of simple Pendulam'); legend('Support rod','Length of Pendulam','Fixed point','Bod of Pendulam'); grid on; hold off; M(ct)=getframe(gcf); ct=ct+1;end
% Inserting Frames in the animation to make moviemovie(M);videofile = VideoWriter('simple_pendulam','uncompressed AVI');open(videofile);writeVideo(videofile,M);close(videofile);
ODE FUNCTION :
function xdot = oed_func(t,x)
b = 0.05; % damping coefficientm = 1; %mass of the pendulamg = 9.81; %Accelaration due gravityl = 1; % length%Assigning nullmatrix to xdotxdot = zeros(2,1);%Rirst element is angular velocity,x(2) positionxdot(1) = x(2);xdot(2)= (-b/m)*x(2)- (g/l)*sin(x(1));
end
PROCEDURE :
- Program should be started with close all clear all &clc.
- Inorder to solve secound order ode we fiest have to convert into 1st order ode and resuld are shored in 2 different columns.
- function is used ode45 is already had been difined in matlab
. - plotting for tracing of angular displacement and angular velocity.
- Animation to the for loop start to plot even position of pendulam in given time interval when ever the for loop.
- We plot [XY] and assing a marker as per requirement to represent the bob of pendulam .
- Title,gride on is used.
- the plot is stored in counter and then the counter is incremented and the loop closed.
- I had get used get frame command and stored in a veriyable named as M(ct).
- Inserting frame in the animation.
- Close the video file.
- And run the code.
OUTPUT :


ANIMATION VIDEO :
VIDEO LINK :
ERRORS :
- No Error
RESULTS :
- To write a program in Matlab to simulate transient behavior of a simple pendulam and cread its animation is successfully complete .