REPORT
given equation is a secound order ordinary differental equation
this ODE reperesents the equation of motion of simple pendulum with damping.
g= gravity in m/s^2 =9.81
l=length of pendulum m =1
m=mass of ball in kg =1
b=damping coefficent =0.05
STEP1
converting the secound order ODE into first order ODE.
we get
d/dt[01;02]=[02;-b/m02 -g/lsin0]
STEP2
this equation is writen as function program in mathlab
function[d theta/dt]=ode_func(t,theta,b,g,l,m)
STEP3:
program for sumalite angular vilosity and angular displacement
inital conditions theta_0=[0.5]
time points t_span= linspace(0,10,500)
solving ODE with values calling the function 'ode_func'
[t,results]=ode45(@(t,theta)0de_func(t,theta,b,g,l,m),t_span,theta_0)
we got the values of t,results
s
STEP4: .
ploting t and results, t in x axis, results y axis than we got plot in screen shot33
STEP 5: ANIMATION
taking counter ct
writing a program using for loop
to creat a pendulam the inital points are X0,y0
thAN X1=lsin
y1=-lcos
using plot command to creat the support line
using line command the creat the pendulam rod line
using plot command and makersize to creat a circle pendulum hingus the support line
using the plot command and makersize commends to creat to draw pendulum bob.
STEP6:
The created animation is convert into the viedo file by using MOVIE command
and saving it in a uncompressed avi formate
https://youtu.be/_YfI7hQgAw8
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
clc
clear all
close all
b=0.05;
g=9.81;
l=1
m=1
% angular displacement=0
%angular velocity = 3rad/sec at time t=0
% inital condations
theta_0=[0,3]
% time points
t_span= linspace(0,20,150)
%solve ODE
[t,results]= ode45(@(t,theta)ode_func(t,theta,b,g,l,m),t_span,theta_0)
%ploting
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel('plot')
xlabel('time')
% animation
X0=0
Y0=0
ct=1
for i=1:length(t_span)
X1=l*sin(results(i,1))
Y1=-l*cos(results(i,1))
%plotting
figure(1)
plot([-1 1],[0 0],'LineWidth',2,'Color','b')
axis([-2 2 -2 2])
line([X0,X1],[Y0,Y1],'linewidth',3,'color','r')
hold on
plot(X0,Y0,'O','MarkerSize',5,'linewidth',3,'Color','g')
plot(X1,Y1,'O','MarkerSize',35,'linewidth',4,'Color','y')
pause(0.001)
grid on
hold off
M(ct)=getframe(gcf);
ct=ct+1
end
movie(M)
videofile= VideoWriter('sec_ODE_p.m','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)