-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpendulum.m
More file actions
34 lines (28 loc) · 712 Bytes
/
Copy pathpendulum.m
File metadata and controls
34 lines (28 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function [X, Y] = pendulum()
%set up initial conditions
G = [pi/4, 0, 0, 0];
endTime = 5;
l = .1;
[t,S] = ode45(@equation, [0,endTime], G);
%unpack the solution
theta1 = S(:,1);
theta2 = S(:,2);
dtheta1 = S(:,3);
dtheta2 = S(:,4);
x1 = l.*sin(theta1);
y1 = -l.*cos(theta1);
x2 = l.*sin(theta1) + l.*sin(theta2);
y2 = -l.*cos(theta1)- l.*cos(theta2);
% hold on;
% plot(t, theta1, 'r-');
% plot(t, theta2, 'b-');
% comet(x1, y1);
% comet(x2, y2);
%plot(t, theta, 'r-');
%comet(theta1,theta2);
xlabel('Theta 1');
ylabel('Theta 2');
title('Pendulum Angle Variation');
X = t;
Y = S;
end