SIMPLE PEND ODE
Video @ https://youtu.be/zVI0960uRGw
(1)
function [dtheta_dt]= ode_func(t,theta,w)
theta1=theta(1)
theta2=theta(2)
dtheta1_dt=theta2;
dtheta2_dt=-(w*w)*sin(theta1);
dtheta_dt=[dtheta1_dt;dtheta2_dt];
end
(2)
%sp
clear all
close all
clc
g=9.81;
l=1;
m=0.1;
w=g/(l*m);
theta_a=[0;1];
t_span = linspace(0,1,500);
[t,results]=ode45(@(t,theta) ode_func(t,theta,w),t_span,theta_a);
angle=results(:,2);
ct=1;
figure(2)
for i=1:500
plot([0,(-l*sin(angle(i)))],[0,(-l*cos(angle(i)))])
hold on
th = 0:pi/50:2*pi;
yunit=0.04*cos(th)+(-l*cos(angle(i)));
xunit=0.04*sin(th)+(-l*sin(angle(i)));
h=plot(xunit,yunit);
axis([-3 3 -3 3])
hold off
pause(0.003)
axis([-3 3 -3 3])
M(ct)= getframe(gcf);
ct=ct+1;
end
movie(M)
videofile = VideoWriter(\'spen.avi\',\'Uncompressed AVI\');
open(videofile)
writeVideo(videofile,M)
close(videofile)
including the theta vs time plot figure also