https://youtu.be/-rNmcEZOlU0
%pendulam
%input
g=9.81;
l=1;
m=1;
b=0.05;
theta=[0;3]; (angular displacement=0 & angular velocity =3 rad/s)
t_span=linspace(0,20,200); (time span from 0-20 sec)
%Solving differential equation
[t,results]=ode45(@(t,theta)ode_eqn(g,l,m,b,t,theta),t_span,theta) (operator for
ordinary differential equation )
%plotting (for loop is used to assign each value of x to X1 and Y1)
x=results(:,1); (array has been made by choosing the first column from the
results array)
ct=1;
for i=1:length(x)
X0=0;
Y0=0;
Y1=-l*cosd(x(i)) (negative value is used so that the pendulam direction can
be reversed)
X1=l*sind(x(i))
%plotting the reference line
plot([-1 1] , [0 0 ],'color','r','LineWidth',3 ) ( A line is plotted passing through the
fixed point where the pendulam moves)
hold on
%plotting the positions of pendulam
plot([X0 X1],[Y0 Y1],'color','b','linewidth',2) (various points of pendulam is plotted
with different values of time)
%plotting the curve
plot( X1,Y1,'marker','o','MarkerSize',30,'Color','k','MarkerFaceColor','k') (path
traced by the pendulam is plotted)
axis([-2 2 -2 2])
pause(0.03)
hold off (hold off restricts the marking of all points )
M(ct)=getframe(gcf); (operator for making frames of different positions of pendulam)
ct=ct+1; (for incrementing the number of frames)
end
% Animation
movie(M)
videofile=VideoWriter('pendulam.avi,matlab video')
open(videofile) (file is opened )
writeVideo(videofile,M) (video is written in the opened file)
close(videofile) (video file is closed)
error in coding: The value X1 and Y1 where interchanged hence the pendulam ball was in upward positions
steps taken to overcome error :All the code where executed step by step and the value of X1 and Y1 are interchanged from the error condition.