Matlab code of simple pendulum, Assignments of Physics

it consists of matlab code that can be used to plot simple pendulum.

Typology: Assignments

2019/2020

Uploaded on 06/26/2020

dionysoser
dionysoser 🇹🇷

5

(1)

1 document

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
%% ************************************%
% Middle East Technical University %
% Department of Mathematics %
% Date: 28.03.2020 %
% Author: Bakican Ayna %
% Number: 2147627 %
%**************************************%
%% ***********************************************************************%
% PLOTS
close all;
set(groot, 'defaultTextInterpreter','latex')
set(groot, 'defaultAxesTickLabelInterpreter','latex');
set(groot, 'defaultLegendInterpreter','latex');
set(0,'defaultFigureUnits','normalized',...
'defaultFigurePosition',[0 0 1 1])
set(0,'defaultLegendFontSizeMode','manual',...
'defaultLegendFontSize',12,...
'defaultErrorBarMarkerSize',12,...
'defaultErrorBarLineWidth',2,...
'defaultLineMarkerSize',12,...
'defaultLineLineWidth',2,...
'defaultAxesFontSize',14)
%% Trajectories for the Simple Pendulum
C = 3.5;
x = linspace(-5*pi,5*pi,10000);
figure (1)
% Case 2 (w^2 = -C)
subplot(221)
y21 = -sqrt(2*(C-C*cos(x)));
y22 = +sqrt(2*(C-C*cos(x)));
plot(x, y21, 'LineWidth', 1.5,'Color',[0,0.5,0.9]); hold on;
plot(x, y22, 'LineWidth', 1.5,'Color',[0,0.5,0.9]); hold on;
xlim([-16 16])
ylim([-20 20])
ylabel('y');
xlabel('x');
title('C = $-\omega^2$');
% Case 3 (-w^2 < C < w^2)
subplot(222)
% w = 2
y31 = -sqrt(2*(C+(2)^2*cos(x)));
y32 = +sqrt(2*(C+(2)^2*cos(x)));
plot(x, y31, 'LineWidth', 1.5,'Color',[0,0.5,0.9],...
'HandleVisibility','off'); hold on;
plot(x, y32, 'LineWidth', 1.5,'Color',[0,0.5,0.9]); hold on;
pf3

Partial preview of the text

Download Matlab code of simple pendulum and more Assignments Physics in PDF only on Docsity!

% Middle East Technical University % % Department of Mathematics % % Date: 28.03.2020 % % Author: Bakican Ayna % % Number: 2147627 % %**************************************% %% ***********************************************************************% % PLOTS close all; set(groot, 'defaultTextInterpreter','latex') set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex'); set(0,'defaultFigureUnits','normalized',... 'defaultFigurePosition',[0 0 1 1]) set(0,'defaultLegendFontSizeMode','manual',... 'defaultLegendFontSize',12,... 'defaultErrorBarMarkerSize',12,... 'defaultErrorBarLineWidth',2,... 'defaultLineMarkerSize',12,... 'defaultLineLineWidth',2,... 'defaultAxesFontSize',14) %% Trajectories for the Simple Pendulum C = 3.5; x = linspace(-5pi,5pi,10000); figure (1) % Case 2 (w^2 = -C) subplot(221) y21 = -sqrt(2(C-Ccos(x))); y22 = +sqrt(2(C-Ccos(x))); plot(x, y21, 'LineWidth', 1.5,'Color',[0,0.5,0.9]); hold on; plot(x, y22, 'LineWidth', 1.5,'Color',[0,0.5,0.9]); hold on; xlim([-16 16]) ylim([-20 20]) ylabel('y'); xlabel('x'); title('C = $-\omega^2$'); % Case 3 (-w^2 < C < w^2) subplot(222) % w = 2 y31 = -sqrt(2(C+(2)^2cos(x))); y32 = +sqrt(2(C+(2)^2cos(x))); plot(x, y31, 'LineWidth', 1.5,'Color',[0,0.5,0.9],... 'HandleVisibility','off'); hold on; plot(x, y32, 'LineWidth', 1.5,'Color',[0,0.5,0.9]); hold on;

% w = 2. y33 = -sqrt(2(C+(2.5)^2cos(x))); y34 = +sqrt(2(C+(2.5)^2cos(x))); plot(x, y33, 'LineWidth', 1.5,'Color',[0,0.5,0.3],... 'HandleVisibility','off'); hold on; plot(x, y34, 'LineWidth', 1.5,'Color',[0,0.5,0.3]); hold on; % w = 3 y35 = -sqrt(2(C+(3)^2cos(x))); y36 = +sqrt(2(C+(3)^2cos(x))); plot(x, y35, 'LineWidth', 1.5,'Color',[0.5,0.2,0.8],... 'HandleVisibility','off'); hold on; plot(x, y36, 'LineWidth', 1.5,'Color',[0.5,0.2,0.8]); hold on; xlim([-16 16]) ylim([-5.5 5.5]) ylabel('y'); xlabel('x'); title('$-\omega^2 < C < \omega^2$'); legend('$\omega = 2.0$','$\omega = 2.5$','$\omega = 3.0$','Location','southeast') % Case 4 (C = w^2) subplot(223) y41 = -sqrt(2(C+Ccos(x))); y42 = +sqrt(2(C+Ccos(x))); plot(x, y41, 'LineWidth', 1.5,'Color',[0,0.5,0.9]); hold on; plot(x, y42, 'LineWidth', 1.5,'Color',[0,0.5,0.9]); hold on; xlim([-16 16]) ylim([-20 20]) ylabel('y'); xlabel('x'); title('C = $\omega^2$'); % Case 5 (C > w^2) subplot(224) % w = 1. y51 = -sqrt(2(C+(1)^2cos(x))); y52 = +sqrt(2(C+(1)^2cos(x))); plot(x, y51, 'LineWidth', 1.5,'Color',[0,0.5,0.9],... 'HandleVisibility','off'); hold on; plot(x, y52, 'LineWidth', 1.5,'Color',[0,0.5,0.9]); hold on; % w = 1. y53 = -sqrt(2(C+(1.5)^2cos(x))); y54 = +sqrt(2(C+(1.5)^2cos(x))); plot(x, y53, 'LineWidth', 1.5,'Color',[0,0.5,0.3],... 'HandleVisibility','off'); hold on; plot(x, y54, 'LineWidth', 1.5,'Color',[0,0.5,0.3]); hold on; % w = 1. y55 = -sqrt(2(C+(1.7)^2cos(x))); y56 = +sqrt(2(C+(1.7)^2cos(x))); plot(x, y55, 'LineWidth', 1.5,'Color',[0.5,0.2,0.8],...