Project

Pendulum

% Pendulum ODE

% Inputs
g = 9.81; %gravity in m/sec^2
L = 1;    %Length in m
m = 1;    %mass in Kg
b = 0.9;  %damping coefficient

%Initial Conditon
x0 = [0;3];

ts = linspace (0,20,100);

[t, R] = ode45(@(t,x) odef(t,x,b,g,L,m), ts, x0);

ct=1;
for q = 1:length(R(:,1))
    j = R(:,1);
        J = j(q);
        
        a0 = 0;
        c0 = 0;
        
        a1 = L*sind(J);
        c1 = -L*cosd(J);
           
        plot([a0 a1],[c0 c1],\'-o\')
        axis([-0.05 0.05 -1.5 1])
        pause(0.0005)
        H(ct) = getframe(gcf);
        ct=ct+1;
end
movie(H)
videofile = VideoWriter(\'Pendulum.avi\',\'Uncompressed AVI\');
open(videofile)
writeVideo(videofile,H)
close(videofile)

Function

function [dx_dt] = odef(t,x,b,g,L,m)

x1 = x(1);
x2 = x(2);
dx1_dt = x2;
dx2_dt = -(b/m)*x2 - (g/L)*sin(x1);
dx_dt = [dx1_dt; dx2_dt];

end

Video

https://drive.google.com/file/d/1vRa9Y_vItmArxNVrea44Lp0tq5P7JQZF/view?usp=sharing

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.