Week 3 - Solving second order ODEs
Solving second order ODEs
AIM :-To write the program motion of simple pendulum by using second order differential equation by using MAT Lab.
To create the plot between Displacement and angular velocity by using ode45.
Theory :-
The simple pendulum is another mechanical system that moves in an oscillatory motion. It consists of a point mass 'm' suspended by means of light inextensible string of length L from a fixed support.
The simple pendulum moves depends on Newton Second law


Ode main program:-
clear all
close all
clc
%inputs
b=0.05;
g=9.81;
l=1;
m=0.1;
%initial coditions
theta_0=[0;5];
%time points
t_span=linspace(0,20,500);
%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));
xlabel('time')
ylabel('plot')
legend('angular displacement','angular velocity')
ct=1;
for i=1:length(t)
x0=0;
y0=0;
x1=l*sin(results(i,1));
y1=-l*cos(results(i,1));
figure(2)
plot([x0,x1],[y0,y1],'color','b')
hold on
plot([1,-1],[0,0],'color','r')
plot(x1,y1,'.','markersize',50)
hold off
axis([-1 1 -1 1])
M(ct)= getframe(gcf);
ct=ct+1;
end
movie(M)
videofile=VideoWriter('simple_pendulaum.avi','uncompressed avi')
open(videofile)
writeVideo(videofile,M)
close(videofile)
Ode 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
Output:-
A plot is drawn between angular acceleration and Displacement of the motion of the simple pendulum

At the end of the t_span both the displacement and angular velocity become zero and the motion of simple pendulum become zero which become the rest.
Conclusion :-
We have animated the simple pendulum using the pde45 solver which the second order is reduced to simple differential equation
Animation is made usin the different points of the bob and the motion of the simple pendulum is created.
Animation video link:-
https://drive.google.com/file/d/1H5XxrqBb7jNVnthGy1qbapM7j1oBGjpM/view?usp=sharing