Week 3 - Solving second order ODEs
clear all
close all
clc
% Inputs
b = 0.05;
g = 9.81;
l = 1;
m = 1;
% Initial condition
theta_0 = [0;3];
% Time points
t = linspace(0,20,500);
x0 = [0,3];
% Solve ODE
[t, results] = ode45(@(t,theta)ode_func(t,theta,b,g,l,m),t,theta_0);
plot(t,results(:,1));
hold on
plot(t,results(:,2));
xlabel('time')
ylabel('plot')
X0=0;
Y0=0;
x = 0;
X1 = 0.5;
Y1 = 0.7;
ct = 1
for i = 1:length(t)
x1 = l*sin(x(i,1));
y1 = -l*cos(x(i,1));
figure(2)
plot([-1 1],[0 0 ],'linewidth',4,'Color','r');
axis([-2 2 -2 2]);
line([X0 X1],[Y0 Y1],'linewidth',1,'color','g');
hold on;
plot(X0,Y0,'O','markersize',3,'markerfacecolor','y');
plot(X1,Y1,'O','markersize',3,'markerfacecolor','auto');
title('damping_of_simple_pendulum');
legend('support_rod','length_of_pendulum','foxed_point','bod_pendulum');
grid on;
hold off;
M(ct)=getframe(gcf);
ct = ct+1;
end
movie(M)
videofile = Videowriter('oscillation_of_pendulum,avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)