clear all
close all
b=0.05
g=9.81
l=1
m=0.1
%intial condition time and displacement
theta_0 =[0 ; 3];
%time point
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);
displacement = results(:,1);
velocity = results(:,2);
%plotting time Vs result (displacement,angular velocity)
figure (1)
plot(t,displacement);
hold on
plot(t,velocity);
ylabel('plot')
xlabel('time')
%plotting pendulum motion
displacement = results(:,1);
velocity = results(:,2);
ct =1;
for i = 1:length(displacement)
string_disp = displacement(i)
x0 = 0;
y0 = 0;
x1 = l*sin(string_disp);
y1 = -l*cos(string_disp);
figure (2)
plot ([x0 x1],[y0 y1],'Color','g','LineWidth',2);
hold on
plot (x1,y1,Marker='o')
hold off
axis([-2 2 -2 2]);
pause(0.05)
M(ct) = getframe(gcf);
ct = ct + 1;
end
movie (M)
videofile = VideoWriter('Pendulum_motion.avi','Uncompressed AVI');
open(videofile);
writeVideo(videofile,M)
close(videofile)