Week 3 - Solving second order ODEs
Objective :
to write a program and understand the motion of simple pendolum by using MATLAB.
THEORY
the simple pendulom haveing a mass M attached to the one end of inextnsible string of length l.and other end of string is attached to the fixed point the
bob is equlibrium condition when external force is applied on it the intial possitin is change with displacement with angle arc in vertical panal
this motion can discribed in mathematical an from a code in matlab an to see the motion of pendolum
pendulum the way the pendolum moves on newtons secoind law low of motion the equation is a can be writen as
mathematical equation is

g = 9.81 accelation du to gravity m/s^2.
l = 1 length of pendolum meter.
m = l mass of the ball kg
b = 0.05 damping co-efficient
procedure
- 2nd oder equation is convert in to a first order becouse we can use easely in use in fucntion
-
creat a funtion ode_pendolum(time,theta,angular displacemet ,gravity,length,mass of bob)
- then calling a function in bult ode45
- input data time t ,theata ,angular displacemernt d ,velocity v,lenght l, mass m , dumping co_efficent b.
- parameter are t theta l g m and b.
- for loop is use to repeat the function of pendulum
- simicolum is used for angular velocity.
ode45 is inbult command which is ordenary equation- the result are stored in 2 columns in the first colum angular displacement value and in the 2nd colume angular due to velocity.
MATLAB CODE :
- To crate a function program for ode_pendolum
function [dtheta_dt] = ode_pendolum(t , theta,b,g,l,m)
thetha1 = theta (1)
theta2 = theta2;
dtheta1_dt = theta2;
dtheta2_dt = (b/m)*theta2 - (g/l*sin(theta1);
dtheta_dt = [dtheta1_dt ; dtheta2_dt];
end
Main program on pendulum
- To creating a main program on pendulum
clear allclose allclcb= 0.1;g= 9.81;l=1;m=0.1;%intial condition% simicolum is used for angular velocitytheta_0 = [0;5];%time points%intial codition change angular displacement with the help oft_span = linspace(0,10,50); % time span with linespace command 0 to 10 second at 50 valuex0=0;y0=0;%solve ODE[t,results] = ode45(@(t,theta) ode_pendolum(t,theta , b,g,l,m ),t_span,theta_0);y= results(:,1);ct=1;for i=1:length(t_span)Y1=y(i);x1 = l*sin(y(i)); y1= -l*cos(y(i));plot([x0 x1],[y0 y1],'linewidth',3,'marker','o')hold onplot(x1, y1, 'marker','o', 'color','g','markersize',30, 'markerfacecolor', 'g')hold offtitle({'Simple harmonic motion'; 'of a pendulum'}, 'color','r')axis([-1 1 -2 0]) % fixed axis in which pendulum stayingpause(0.03)M(ct)= getframe(gcf);ct=ct+1;end%movie commands
movie(M)videofile = VideoWriter('pendulum.avi', 'Uncompressed AVI');open(videofile)writeVideo(videofile,M)close(videofile)y = results(:,1)plot(t,results(:,1));hold onplot(t,results(:,2));xlabel('Time');ylabel('Displacement');title('Pendolum variation of time vs displacemet');
conclution:
writeing a simple program on pendulum and the animited video is created.