You are on page 1of 13

3D Spherical Pendulum Motion Modelling and Analysis

April 14, 2008


Abstract
3D Spherical pendulum motion is modeled with second-order differential equation.
Some indirect tests are executed to check the performance of the methods, since the
exact solution is not available. Given initial position and velocity, Crank-Nicolson and
Runge-Kutta methods (ode23) are comparably outperforming other methods in terms
of calculation time.

Introduction

A pendulum is connected to massless bar with length 1 that is fixed at (x1 , x2 , x3 ) = (0, 0, 0).
It is assumed that the movement of the pendulum is restricted to spherical surface. The pendulmum with mass m moves under the influence of gravity F in -x3 direction. 3D Spherical
pendulum motion is modelled with second-order differential equation. This second order differential equations are transformed into a systme of six, coupled first-order differential equation. Forward Euler, backward Euler, Crank-Nicolson and 2 built-in Runge-Kutta (ode23,
ode45) functions are used to test the performance of the methods and analyses the results.
Since we do not know the exact solution of this problem, we use numerical method to predict
the time series of pendulum position and velocity. For the test of methods some physical
quatities such total energy, angular momentum will be calculated.

Method

The motion of a particle positioned at x(t) = (x1 (t), x2 (t), x3 (t)) with mass m subject to the
force F = (0, 0, mg) of spherical pendulum can be described by the second-order differential
equation
!
mx T H x + T F
1
F

(1)
x =
m
||2
, where (x) = x21 + x22 + x23 1 = 0 is the unit sphere and the particle is moving and H is
the Hessian matrix of with components
Hij =

2
.
xi xj
1

(2)

In this case, = 2x and H is a diagonal matrix with each diagonal element equal to 2.
This second order differential equation can be transformed into a system of six, coupled
first-order differential equations.
Let y = [x1 , x2 , x3 , x1 , x2 , x3 ]T . Then we obtain system
y i = y3+i
y 3+i

(3)
!

=
F
, i = 1, 2, 3
m
yi

(4)

,where
m(y4 , y5 , y6 )H(y4 , y5 , y6 )T T F
.
(5)
||2
To simplify the problem, mass(m) and gravitational acceleration(g) are set to 1Kg, 9.8m/s 2 ,
respectively.
=

Result and Analysis

3D trajectory, spherical movement, total energy and angular momentum component (x3
direction) were computed and plotted for modelling and analysis of spherical pendulum.
Ideally a method should show constant total energy (1.04 Joule) and angular momentum
(0.8m2 /s) (0m2 ). For the computation performance comparison, time step dependence was
checked for forward, backward and Crank-Nicolson method. In 3D plot in this paper, 3D
space is represented by x,y,z axis which are corresponding (x1 , x2 , x3 ). In 2D plot unit of
phi, Total energy and Lz are m2 , Joule and Kg m2 /s, respectively.
In figure 1, forward Euler method of time step 0.01 result in accumulation of errors in
total energy and shows that the pendulum does not move on the spherical surface. Time
step of 0.001 resulted in stable those physical quantities (Figure 3) which took a lot of
computational time. Same case as in forward Euler method, in figure 4 of time step 0.01
result in accumulation of errors in total energy and predicts that pendulum does not move on
the spherical surface which is not satisfying movement constraint Time step of 0.001 resulted
in stable those physical quantities (Figure 3) which took a lot of computational time.
However, in Crank-Nicolson method of time step 0.01 result in accumulation of very small
errors in total energy and predicts that pendulum moves on the spherical surface which is
satisfying movement constraint and constant other test quantities (figure 7-9). Figure 10,
11 shows Runge-Kutta methods (ode23, ode45). Compared to those previous three methods
took a relatively very short compulation time. The built-in methods take flexible time step.
ode23 outperforms ode45 in this pendulum problem.

conclusion

Spherical pendulum was modelled with second-order differential equation by splitting into a
systme of six, coupled first-order differential equations. Out of test methods, Crank-Nicolson
and Runge-Kutta methods (ode23) showed higher performance than other methods in terms
of calculation time.
2

Forward Euler
2
1

2
2

1
0
y

2
0
2 2

x
2

1
z

Total Energy

1
2

10
15
Time (sec)

20

25

10
15
Time (sec)

20

25

0
1

10
15
Time (sec)

20

25

Figure 1: Forward Euler method with H (time step) 0.01.


2
1

2
2

1
0
y

2
0
2 2

x
2

1
z

Total Energy

1
2

10
15
Time (sec)

20

25

10
15
Time (sec)

20

25

0
1

10
15
Time (sec)

20

25

Figure 2: Forward Euler method with H (time step) 0.001.


Forward Euler
2
1

2
2
0
y

2
0
2 2

x
2

1
z

Total Energy

0
1

1
2

10
15
Time (sec)

20

25

10
15
Time (sec)

20

25

0
1

10
15
Time (sec)

20

25

Figure 3: Forward Euler method with H (time step) 0.0001.


3

Backward Euler
2
1

2
2

1
0
y

2
0
2 2

x
2

1
z

Total Energy

1
2

10
15
Time (sec)

20

25

10
15
Time (sec)

20

25

0
1

10
15
Time (sec)

20

25

Figure 4: Backward Euler method with H (time step) 0.01.


Backward Euler
2
1

2
2

1
0
y

2
0
2 2

x
2

1
z

Total Energy

1
2

10
15
Time (sec)

20

25

10
15
Time (sec)

20

25

0
1

10
15
Time (sec)

20

25

Figure 5: Backward Euler method with H (time step) 0.001.


Backward Euler
2
1

2
2
0
y

2
0
2 2

x
2

1
z

Total Energy

0
1

1
2

10
15
Time (sec)

20

25

10
15
Time (sec)

20

25

0
1

10
15
Time (sec)

20

25

Figure 6: Backward Euler method with H (time step) 0.0001.


4

Crank Nicolson
2
1

2
2

1
0
y

2
0
2 2

x
2

1
z

Total Energy

1
2

10
15
Time (sec)

20

25

10
15
Time (sec)

20

25

0
1

10
15
Time (sec)

20

25

Figure 7: Crank-Nicolson method with H (time step) 0.01.


Crank Nicolson
2
1

2
2

1
0
y

2
0
2 2

x
2

1
z

Total Energy

1
2

10
15
Time (sec)

20

25

10
15
Time (sec)

20

25

0
1

10
15
Time (sec)

20

25

Figure 8: Crank-Nicolson method with H (time step) 0.001.


Crank Nicolson
2
1

2
2
0
y

2
0
2 2

x
2

1
z

Total Energy

0
1

1
2

10
15
Time (sec)

20

25

10
15
Time (sec)

20

25

0
1

10
15
Time (sec)

20

25

Figure 9: Crank-Nicolson method with H (time step) 0.0001.


5

2
1

2
2
0
y

2
0
2 2

x
2

1
z

Total Energy

0
1

1
2

10
15
Time (sec)

20

25

10
15
Time (sec)

20

25

0
1

10
15
Time (sec)

20

25

Figure 10: Runge-Kutta method (ode23)

2
1

2
2

1
0
y

2
0
2 2

x
2

1
z

Total Energy

1
2

10
15
Time (sec)

20

25

10
15
Time (sec)

20

25

0
1

10
15
Time (sec)

20

25

Figure 11: Runge-Kutta method (ode45)

Software

In this modeling 5 Matlabscript files were created.


%driver_P2
%This matlab m-file is a driver program for forward euler, backward euler,
% crank nicolson and runge-kutta method.
y1=[0,1,0,0.8,0,1.2];
%Initial position and velocity
m=1; g=9.8;F=[0,0,-m*g] ;
%Mass, gravity acceleration and

Force (weight)

%===================================================
% Three time step : h= 0.001, 0.01, 0.0001
%===================================================
h=0.001;
%Time step for forward, backward euler and crank-nicolson method
t1=0; tf=25;
t = t1:h:tf;
%Initial and Final time
%=================================================
%% Driver for forward euler
u =feuler_P2(@ode1_P2, t1,tf,h,y1);
figure(1)
% 3D trajectory plotting
subplot(2,2,1)
plot3(u(:,1),u(:,2),u(:,3))
title(Forward Euler);
grid on
xlabel(x);
ylabel(y);
zlabel(z);
set(gca,XLim,[-2 2],YLim,[-2 2], ZLim,[-2 2]);
%Particle constraint plot (Phi)
subplot(2,2,2)
phi=u(:,1).*u(:,1)+u(:,2).*u(:,2)+u(:,3).*u(:,3)-1;
plot(t,phi)
xlabel(Time (sec));
ylabel(\phi);
7

set(gca,XLim,[0 25],YLim,[-2 2]);


%Total energy plot
subplot(2,2,3)
energy=1/2*(u(:,4).*u(:,4)+u(:,5).*u(:,5)+u(:,6).*u(:,6))+9.8*u(:,3);
plot(t,energy)
xlabel(Time (sec));
ylabel(Total Energy);
set(gca,XLim,[0 25],YLim,[-2 2]);
%Angular momentum conservation
subplot(2,2,4)
Lz=(u(:,1).*u(:,5)-u(:,2).*u(:,4));
plot(t,Lz)
xlabel(Time (sec));
ylabel(L_z);
set(gca,XLim,[0 25],YLim,[-2 2]);

%=================================================
%% Driver for backward euler
u =beuler_P2(@ode1_P2, t1,tf,h,y1);
figure(2)
% 3D trajectory plotting
subplot(2,2,1)
plot3(u(:,1),u(:,2),u(:,3))
grid on
title(Backward Euler);
xlabel(x);
ylabel(y);
zlabel(z);
set(gca,XLim,[-2 2],YLim,[-2 2], ZLim,[-2 2]);
%Particle constraint plot (Phi)
subplot(2,2,2)
phi=u(:,1).*u(:,1)+u(:,2).*u(:,2)+u(:,3).*u(:,3)-1;
plot(t,phi)
xlabel(Time (sec));
ylabel(\phi);
set(gca,XLim,[0 25],YLim,[-2 2]);
%Total energy plot
8

subplot(2,2,3)
energy=1/2*(u(:,4).*u(:,4)+u(:,5).*u(:,5)+u(:,6).*u(:,6))+9.8*u(:,3);
plot(t,energy)
xlabel(Time (sec));
ylabel(Total Energy);
set(gca,XLim,[0 25],YLim,[-2 2]);
%Angular momentum conservation
subplot(2,2,4)
Lz=(u(:,1).*u(:,5)-u(:,2).*u(:,4));
plot(t,Lz)
xlabel(Time (sec));
ylabel(L_z);
set(gca,XLim,[0 25],YLim,[-2 2]);
%=================================================
% Driver for crank-nicolson
u =cranknic_P2(@ode1_P2, t1,tf,h,y1);
figure(3)
% 3D trajectory plotting
subplot(2,2,1)
plot3(u(:,1),u(:,2),u(:,3))
grid on
title(Crank Nicolson);
xlabel(x);
ylabel(y);
zlabel(z);
set(gca,XLim,[-2 2],YLim,[-2 2], ZLim,[-2 2]);
%Particle constraint plot (Phi)
subplot(2,2,2)
phi=u(:,1).*u(:,1)+u(:,2).*u(:,2)+u(:,3).*u(:,3)-1;
plot(t,phi)
xlabel(Time (sec));
ylabel(\phi);
set(gca,XLim,[0 25],YLim,[-2 2]);
%Total energy plot
subplot(2,2,3)
energy=1/2*(u(:,4).*u(:,4)+u(:,5).*u(:,5)+u(:,6).*u(:,6))+9.8*u(:,3);
plot(t,energy)
xlabel(Time (sec));
ylabel(Total Energy);
set(gca,XLim,[0 25],YLim,[-2 2]);
9

%Angular momentum conservation


subplot(2,2,4)
Lz=(u(:,1).*u(:,5)-u(:,2).*u(:,4));
plot(t,Lz)
xlabel(Time (sec));
ylabel(L_z);
set(gca,XLim,[0 25],YLim,[-2 2]);

%=================================================
%Runge-Kutta
[t,u] = ode23(@ode1_P2,[t1 tf],y1);
figure(4)
% 3D trajectory plotting
subplot(2,2,1)
plot3(u(:,1),u(:,2),u(:,3))
grid on
xlabel(x);
ylabel(y);
zlabel(z);
set(gca,XLim,[-2 2],YLim,[-2 2], ZLim,[-2 2]);
%Particle constraint plot (Phi)
subplot(2,2,2)
phi=u(:,1).*u(:,1)+u(:,2).*u(:,2)+u(:,3).*u(:,3)-1;
plot(t,phi)
xlabel(Time (sec));
ylabel(\phi);
set(gca,XLim,[0 25],YLim,[-2 2]);
%Total energy plot
subplot(2,2,3)
energy=1/2*(u(:,4).*u(:,4)+u(:,5).*u(:,5)+u(:,6).*u(:,6))+9.8*u(:,3);
plot(t,energy)
xlabel(Time (sec));
ylabel(Total Energy);
set(gca,XLim,[0 25],YLim,[-2 2]);
%Angular momentum conservation
subplot(2,2,4)
Lz=(u(:,1).*u(:,5)-u(:,2).*u(:,4));
plot(t,Lz)
xlabel(Time (sec));
10

ylabel(L_z);
set(gca,XLim,[0 25],YLim,[-2 2]);
%=================================================
%Runge-Kutta
[t,u] = ode45(@ode1_P2,[t1 tf],y1);
figure(5)
% 3D trajectory plotting
subplot(2,2,1)
plot3(u(:,1),u(:,2),u(:,3))
grid on
xlabel(x);
ylabel(y);
zlabel(z);
set(gca,XLim,[-2 2],YLim,[-2 2], ZLim,[-2 2]);
%Particle constraint plot (Phi)
subplot(2,2,2)
phi=u(:,1).*u(:,1)+u(:,2).*u(:,2)+u(:,3).*u(:,3)-1;
plot(t,phi)
xlabel(Time (sec));
ylabel(\phi);
set(gca,XLim,[0 25],YLim,[-2 2]);
%Total energy plot
subplot(2,2,3)
energy=1/2*(u(:,4).*u(:,4)+u(:,5).*u(:,5)+u(:,6).*u(:,6))+9.8*u(:,3);
plot(t,energy)
xlabel(Time (sec));
ylabel(Total Energy);
set(gca,XLim,[0 25],YLim,[-2 2]);
%Angular momentum conservation
subplot(2,2,4)
Lz=(u(:,1).*u(:,5)-u(:,2).*u(:,4));
plot(t,Lz)
xlabel(Time (sec));
ylabel(L_z);
set(gca,XLim,[0 25],YLim,[-2 2]);

11

% ===============================================
function u = feuler_P2(f, t1, tf, h,y1)
%Forward Euler Method
t = t1:h:tf;
%time array
n = length(t);
%number of time
u=zeros(n,6);
% making two dimensional matrix

nx2

u(1,:) = y1;
for k = 1:n -1
u(k+1,:) = u(k,:) + h.*f(t(k), u(k,:));
end
%=====================================================
function u = beuler_P2(f, t1, tf, h, y1)
%Forward Euler Method
t = t1:h:tf;
%time array
n = length(t);
%number of time
u=zeros(n,6);
u(1,:) = y1;
opts=optimset;
opts.Display=off;
opts.TolFun=1.0e-12;
opts.MaxFunEvals=1e4;
for k=1:n-1
u(k+1,:)=(fsolve(@(w) nonlinfun(w,k,u,h,f,t),u(k,:), opts));
end
function z=nonlinfun(w,k,u,h,f,t)
z=u(k,:) -w + h*f(t,w);

% =========================================================
12

function f=ode1_P2(t,y)
%ode model
m=1;
g=9.8;
F=[0,0,-m*g]

H=[2,0,0; 0,2,0; 0,0,2];


x=[y(1),y(2),y(3)];
v=[y(4),y(5),y(6)];
f=zeros(6,1);
f(1)=v(1);
f(2)=v(2) ;
f(3)=v(3) ;
f(4)= 1/m*(F(1)-((m*v*H*v+2*x*F)/(4*x*x))*2*x(1));
f(5)= 1/m*(F(2)-((m*v*H*v+2*x*F)/(4*x*x))*2*x(2));
f(6)= 1/m*(F(3)-((m*v*H*v+2*x*F)/(4*x*x))*2*x(3));

13

You might also like