Uploaded by Stokes Wallis

expphyfin ver 2 (1)

advertisement
Spring Pendulum Simulation
Building a computer simulation capable of accurately predicting nontrivial physical system is a
vital ability of a modern physicist. Our goal in this experiment is to explore the complications
that arise while building the computer simulation of a spring pendulum. We aim to explain the
simulation method and explore what causes our simulation to fail or become far from reality.
I.
INTRODUCTION
In physics, theories can usually describe how a simple
system behaves with a mathematical equation to a high
degree of precision. However, when the system of interest
is composed of a combination of simple systems, a simple mathematical solution to describe its behaviour often
ceases to exist.
It is of interest to humans to be able to predict many
such systems. For example: being able to predict Earth’s
climate enables governments of the world to make preparations against upcoming changes and set reasonable carbon emission goals; being able to rule out flaws in the design of a rocket before launch can save trillions of dollars
and the lives of astronauts. This is why computer experiments have such an important place in modern science,
it provides the means to provide a reasonable prediction
of systems which are too complicated to calculate or are
too expensive to perform live trials on. As such, acquiring
the ability to build a computer simulation of real-world
physics is vital for a modern physicist.
With this purpose in mind, we’ve elected to build a
computer simulation of a system which combines two elementary system in classical mechanics: springs and pendulums. We attempted to simulate a system in which a
point mass experiences a combination of constant gravity and the pull of a massless spring, which is connected
between the point mass and the origin. The combination
of these two produces a system that produces chaotic
behaviour, for which analytic solutions expressed in elementary functions do not exist. Thus, such a system
requires computer simulation to predict its future state
if the current initial conditions are observed.
II.
MATERIALS AND METHODS
We use the program MATLAB to run our simulations,
and employ two approaches to simulate the spring pendulum. The first approach is by iteration: using the
fundamental equation,
F = ma
, we can change the velocity (or angular velocity) according to the acceleration (or torque) it experiences at that
moment over an infinitesimal period of time to its current
velocity. As long as the time-step is reasonably small, the
simulation will be reasonably representative of the actual
behaviour. The second approach utilizes what was taught
during the end of this semester in theoretical mechanics
and the ODE solving capability of MATLAB: by using
the ode45 function, MATLAB can numerically solve the
two ODEs derived from the system’s Lagrangian.
The equation of motion is:

r̈ +

kr
m
−
kd
m
− gcosθ = 0
(1)
θ̈ + gr sinθ
= 0
We also explored MATLAB’s ability to represent the solution graphically or with animations, as the information
of a graph or an animation is more easily digested compared to numbers. The specific methods we explored include: telling MATLAB to draw on the same plot every
time the for-loop repeats while incorporating a 0.1 second pause for every loop; using the ”drawnow” command
to add geometric objects to our animation to represent
the point mass.
III.
RESEARCH PROCESS
In this section, we will introduce how we did the simulation and what we had done. To check our code can
be used in simulation or not, we first consider the simple
pendulum. The equation of motion (EM) of simple pendulum and spring pendulum are not linear and their analytical solution can’t be expressed by elementary functions. Therefore, we have to our numerical method to
approach it.
At first, we used the simplest form of iteration, the
Euler method, to approach the solution. However, we
quickly discovered that the total energy of the simulation
increases very quickly even over a very short duration.
Shortening the time-step between iterations helped slow
down the rate at which the total energy rises, but the
time required for the computer increases drastically. It
soon became impractical as we needed to wait more than
10 minutes for the computer to complete a 10 second
simulation.
We then tried another method: ode45. It is based
on the Runge-Kutta method, and it would automatically
take an appropriate time step to make simulation. Most
importantly, it is able to complete the simulation of longduration trials in a matter of seconds. Here are the simple
pendulum case based on ode45 (The initial angle goes
from 0 to π/2 at an interval of π/16) :
2
(a) Phase plot of simple pendulum(50s)
(a) Initial angle π/16
(b) Phase plot of simple pendulum(100s)
FIG. 1. Different Simulation Time
We can observe that for small angle, the solution is
satisfactory. However, the closed loop gradually widens
over time as the simulation duration and initial angle
increases. It is clear that the energy is nearly conserved
in this system. However, longer simulation inevitably
causes the increase to become apparent. Therefore, we
will keep all our following simulations under 50 seconds.
(b) Initial angle π/8
We want to apply the same method to spring pendulum. Here we plot the potential energy against the
kinetic energy. If the total energy is conserved, the plot
should be a straight line.
We make the simulation with:
k = 10, m = 1, r(0) = 5, d = 2, and no initial velocity.
The energy is given by:
U=
1
k(r − d)2 − mgrcosθ
2
(2)
(c) Initial angle π/6
FIG. 2. Different Initial angle
T =
1 2 1 2 2
mṙ + mr θ̇
2
2
(3)
We can observe that the larger the initial angle be-
3
comes, the wider the plot gets. That is, for a larger
initial angle, though total energy is still bounded, the error(difference with reality) is larger. We have tried different ode solver, such as ode23, ode113, ode15s, we found
that ode45 can approach relatively exactly. Therefore,
in the following section, we are going to find the reason behind this phenomenon, and we would discuss the
difference behavior with lower error situation.
IV.
route back and forth. We determine that the motion in
this situation can not be defined as chaos since it just
went through the specific point.
In this part, we change our initial length to 6 meter, and the simulation stopped at 1 second. We thought
that the reason behind this failure is due to the spring
compressing more than it possibly could. In this case,
the compression length is longer than its natural length.
In reality, this situation would not happen.
RESULT AND DISCUSSION
The following plots are the results of our simulations.
First, we make an (r,θ)-Time Plot and a spacial plot
showing the trajectory of the spring pendulum under the
initial conditions: k = 10, m = 1, r(0) = 5, d = 2, no
initial velocity.
As we further varied the initial conditions, we discovered another case where θ resembles SHM but r does not.
The initial conditions are: m = 1, k = 10, d = 10, r(0) =
10, θ(0) = π/3, and no initial velocity. The potentialkinetic energy plot is:
(a) Position(r,θ)-Time Plot
FIG. 4. Potential-Kinetic energy plot
(b) x-y(2D space) plot
FIG. 3. Spring pendulum example1
In example 1, we can observe that the the motion in
the r direction (the direction of the spring) resembles
simple harmonic motion, and the θ direction has a seemingly chaotic behaviour. However, we can observe than
the motion repeats itself every three peaks. Therefore,
the motion under these initial conditions has regularity.
In figure3(b), the mass point goes through the specific
We observe that in this case, the value of total energy
doesn’t change a lot, the slope of these spots (according
to the curve fitting tool) is almost -1 and the distribution
of spots are not too wide. That is, this simulation is good
enough to simulate the real situation. Then we started
to make the same two plots as we made in figure 3:
4
(a) Position(r,θ)-Time Plot
(b) x-y(2D space) plot
FIG. 5. Spring pendulum example2
We can notice that under this initial condition, the
r and θ exchange their roles. Three peaks of r form a
period just as θ was, and the θ wave resembles SHM.
As previously said, we classify this kind of situation as
periodic motion but not chaos. We had also simulated
different initial conditions, we just take the simplest two
examples to show our result.With above two examples,
we can make the conclusions.
First, with different initial conditions, to check the
simulation whether close to reality or not, we make
the energy(potential and kinetic) to check the total
energy or not. If we get the almost conserved energy,
the simulation is a good approximation and vice versa.
In our researching process, we notice that it is hard to
tell whether the simulation is good or not by checking
initial conditions. When the initial angle becomes larger,
iteration via Euler method loses accuracy, but ode45
doesn’t. We also found that the simulation duration
does not affect the accuracy of ode45 i.e. the width of
the potential-kinetic plot does not increase when the
simulation time lengthens. To get a more exact solution,
reducing the time step is the best way, but it takes a lot
of time. And the accuracy is not affected by just one of
the initial conditions, but many of them at once.
Second, we are going to compare the difference between
the two examples we listed. In example 1, we extended
the spring a lot initially, while in example 2, we let the
spring maintain its natural length. The behaviour of r
and θ differs drastically in these two cases. By the Lagrangian equations listed in section two, we notice that
the r-directional motion and the θ-directional motion of
the point mass are not independent of one another. In
the first example, the initial angle is small, but the length
was extended a lot. The erratic behaviour of θ can be
explained by equation 1-2: the angular acceleration is
erratic because r changes very frequently.
And in example 2, the reverse is true. Then rdirectional position behaves erratically because of the
rapid change of θ. If we take small perturbation in both
direction, it would become the simple pendulum. We
tried to simulate the system with larger initial angle
and extension, but the energy of the system increased
too rapidly. We think that we have to use advanced
computer to make more accurate simulations of these
extreme initial conditions.
Through this project, we learned more about how to
use MATLAB to solve physics problems and use numerical methods to solve ode. We also found how to make
animation using MATLAB. However, as animations
can’t be shown in the form of written report, we’ve
attached the code in our appendix (where we hand in
the code). Though we did not use MATLAB to solve
more complex or difficult problem, we have begun to use
different thinking and method to solve physical problems.
Download