visualizing-pendulum-motion
the ode function is given as
function [dtheta_dt]=ode_func(t,theta,w)
theta1=theta(1)
theta2=theta(2)
dtheta1_dt=theta2;
dtheta2_dt= -(w^2)*sind(theta1);
dtheta_dt=[dtheta1_dt;dtheta2_dt]
end
the main program
clear all
close all
clc
g=9.81;
l=1;
m= 0.1;
w=g/(l*m);
%initial condition
theta_0=[ 0;100];
%time span
t_span=linspace(0,50,100);
%integration
[t , results]=ode45(@(t,theta) ode_func(t,theta,w), t_span , theta_0);
%plotting
figure(1)
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel(\'VELOCITY/DISPLACEMENT\')
xlabel(\'TIME\')
%animation
ct=1;
for i=1:length(t_span)
THETA=results(i,1);
%string
x0=0;
y0=0;
x=x0-l*sind(THETA);
y=y0-l*cosd(THETA);
figure(2)
plot([x0 x],[y0 y],\'color\',\'g\',\'linewidth\',2)
axis([ -1.3 1.3 -1.3 1.3]);
%ball
centre=[x y];
circle=viscircles(centre,0.2)
M(ct)=getframe(gcf);
ct=ct+1;
end
movie(M)
videofile=VideoWriter(\'Pendulum_matlab.avi\',\'Uncompressed AVI\');
open(videofile)
writeVideo(videofile,M)
close(videofile)
please visit this link for output
https://drive.google.com/open?id=1aOxqAkTV0wSstO2KY84Gd-iUK2Ltu0s-