Week 4.1 - Solving second order ODEs
plotting
close all
clear all
clc
% inputs
b = 0.05;
g = 9.81;
l = 1;
m = 0.1;
% intial condition
theta_0 = [0;5];
% time points
t_span = linspace (0,10,500);
% slove ODE
[t,result] = ode45(@(t,theta)oun_func(t,theta,b,g,l,m),t_span,theta_0);
plot(t,result(:,1))
hold on
plot(t,result(:,2))
xlabel('time')
ylabel('time')
animation plotting
close all
clear all
clc
% inputs
b = 0.05;
g = 9.81;
l = 1;
m = 0.1;
% intial condition
theta_0 = [0;5];
% time points
t_span = linspace (0,10,500);
% slove ODE
[t,result] = ode45(@(t,theta)oun_func(t,theta,b,g,l,m),t_span,theta_0);
plot(t,result(:,1))
hold on
plot(t,result(:,2))
xlabel('time')
ylabel('time')
ct = 1;
theta = result(:,1)
for i = 1:length(t_span)
r = theta(i)
x0 = 0;
y0 = 0;
x1 = l*sin(r);
y1 = -l*cos(r);
figure(2)
plot([x0 x1],[y0 y1],'linewidth',10)
hold on
plot(x1,y1,'.','markersize',50)
hold on
plot([-5 5],[0 0],'linewidth',4)
hold off
axis([-9 9 -4 4])
pause(0.01)
M(ct) = getframe(gcf);
ct = ct+1;
end
create movie
close all
clear all
clc
% inputs
b = 0.05;
g = 9.81;
l = 1;
m = 0.1;
% intial condition
theta_0 = [0;5];
% time points
t_span = linspace (0,10,500);
% slove ODE
[t,result] = ode45(@(t,theta)oun_func(t,theta,b,g,l,m),t_span,theta_0);
plot(t,result(:,1))
hold on
plot(t,result(:,2))
xlabel('time')
ylabel('time')
ct = 1;
theta = result(:,1)
for i = 1:length(t_span)
r = theta(i)
x0 = 0;
y0 = 0;
x1 = l*sin(r);
y1 = -l*cos(r);
figure(2)
plot([x0 x1],[y0 y1],'linewidth',10)
hold on
plot(x1,y1,'.','markersize',50)
hold on
plot([-5 5],[0 0],'linewidth',4)
hold off
axis([-9 9 -4 4])
pause(0.01)
M(ct) = getframe(gcf);
ct = ct+1;
end
movie(M)
videofile = VideoWriter('Ranjith.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)
videolink : https://youtu.be/NOqIuDV2qb0