Project

Second Order ODE

clear all
close all
clc
%Inputs for the second order ODE equation

b= 0.02;
q= 9.81;
l= 1;
m = 0.1;

%angle of theta wrt time
theta_0 = [0;4];

% time
t_span = linspace(0,10,200);
%Solve ODE
[t,results] = ode45(@(t,theta) ode_func(t,theta,b,q,l,m),t_span,theta_0);
plot(t,results(:,1));
hold on
plot(t,results(:,2));
xlabel('time');
ylabel('displacement of velocity');
title('damping of pendulum');
ct=1;
for i= 1:length(results(:,1));
    
    x0 = 0;
    y0 = 0;
     x1= -1*sin(results(i,1));
     y1 = 1*cos(results(i,1));
     subplot(5,4,[1,2,3,4,5,6,7,8,9,10,11,12]);
     plot([1,-1],[0,0],'linewidth',3);
     hold on
     line([x0 x1],[y0 y1],'linewidth',1,'color','b');
     hold on
     plot(x1,y1,'-o','markersize',20,'markerfacecolor','g');
     pause(0.003);
     axis([-1.5,1.5,-1.5,.5]);
     grid on;
     hold off
     G(ct) = getframe(gcf);
     ct = ct+1;
end


movie(G)
videofile = VideoWriter('second_order_ODE.avi','uncompressed.avi');
open(videofile);
writevideo(videofile,G);
close(videofile)
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.