-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPendulum.m
40 lines (33 loc) · 816 Bytes
/
Pendulum.m
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
35
36
37
38
39
% Author: Tongkui Su
% This script simulates the motion of a simple pendulum
% using three different numerical methods: (Forward)Euler, BackwardEuler,
% SemiEuler
% Variables
m=1;
L=9.81;
g=9.81;
theta=(1/10)*pi;
omega=0;
tf = 20; %time from 0 to tf
N = 200;
h=tf/N;
hold off;
ax=gca;
scatter(ax,0, 0, 'bo');
axis(ax,[-L-1, L+1, -L-1, L+1]);
axis equal;
hold on;
title('SemiEuler');
pause;
% Compute
while 1
%[theta,omega] = Euler(omega, theta, h, g, L);
%[theta,omega] = BackEuler(omega, theta, h, g, L);
[theta,omega] = SemiEuler(omega, theta, h, g, L);
item1=line(ax,[0,L*sin(theta)], [0, -L*cos(theta)],'Color',[0.2,0.4,1]);
item2=scatter(ax,L*sin(theta), -L*cos(theta), 'bo');
axis(ax,[-L-1, L+1, -L-1, L+1]);
pause(0.01);
item1.delete;
item2.delete;
end