Project

Oscillations of Pendulum using function for solving of Second Order Ordinary Differential Equations

clear all
close all
clc
%inputs
b=0.05;
l=1;
g=9.81;
m=1;
theta_0 = [0;3];
t_span=linspace(0,20,600);
%function
[t,Results]=ode45(@(time,theta) ode_func(time,theta,b,g,l,m), t_span, theta_0);
%for loop
for i=1:length(Results(:,1))
%displacement & velocity plot
subplot(5,4,[13,14,17,18]);
plot(t,Results(:,1),\'color\',\'b\');
hold on;
plot(t,Results(:,2),\'color\',\'r\');
hold off;
%angular position
subplot(5,4,[15,16,19,20]);
plot(Results(:,1),Results(:,2));
xlabel(\'Position_Radians\');
ylabel(\'Angular Velocity\');
% pendulum position co-ordinates
x0=0;
y0=0;
x1=l*-sin(Results(i,1));
y1=l*cos(Results(i,1));
subplot(5,4,[1,2,3,4,5,6,7,8,9,10,11,12]);
%plotting fixed support
plot([-1,1],[0,0],\'linewidth\',4,\'color\',\'r\');
hold on;
%pendulum handle
line([x0 x1],[y0 -y1],\'linewidth\',2,\'color\',\'b\');
hold on;
%pendulum bob
plot(x1,-y1,\'-o\',\'markers\',20,\'markerfacecolor\',\'y\');
grid on;
axis([-1.5 1.5 -1.5 0.5])
pause(0.003);
hold off;
end

\"pendulum1\"

\"pendulum2\"

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.