Project

pendulum

% solving differential equation of second order (motion of a damped pendulum)
% x\'\' + (b/m)*x\' + g*sin(x)/l = 0

[t state_values] = ode45(@pend,[0 4],[0 4]);
plot(t,state_values(:,1),\'linewidth\',1,\'color\',\'r\')
hold on;
plot(t,state_values(:,2),\'linewidth\',1,\'color\',\'b\')

legend(\'angular displacement vs time \',\'angular velocity vs time\');

% simulation of an oscillating pendulum for one time period of 5 sec(1 oscillation actually takes approx 5 sec due to internal code between two for loops)
% time period = 5 sec
% g = 10 m/s^2
% so length of pendulum = 4.0528 m

close all; clear all; clc

l = 4.0528;


for j = 1:4
theta = linspace(255,285,35);
for i = 1:length(theta)
ang = theta(i);
x0 = 0;
y0 = 0;
x1 = l*cosd(ang);
y1 = l*sind(ang);

plot([x0 x1],[y0 y1],\'linewidth\',2,\'color\',\'r\')
axis([-5 5 -5 5]);
pause(0.04)
end


theta = linspace(285,255,35);

for i = 1:length(theta)
ang = theta(i);
x0 = 0;
y0 = 0;
x1 = l*cosd(ang);
y1 = l*sind(ang);

plot([x0 x1],[y0 y1],\'linewidth\',2,\'color\',\'r\')
axis([-5 5 -5 5]);
pause(0.04)
end

end

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.