Runge-Kutta - Numerical Solutions of Differential Equations

Similar documents
Determination of Acceleration due to Gravity

Experiment 9. The Pendulum

AP1 Oscillations. 1. Which of the following statements about a spring-block oscillator in simple harmonic motion about its equilibrium point is false?

Spring Simple Harmonic Oscillator. Spring constant. Potential Energy stored in a Spring. Understanding oscillations. Understanding oscillations

PENDULUM PERIODS. First Last. Partners: student1, student2, and student3

EXPERIMENT 2 Measurement of g: Use of a simple pendulum

AP Physics C. Oscillations/SHM Review Packet

Simple Harmonic Motion Experiment. 1 f

Physics 41 HW Set 1 Chapter 15

Simple Harmonic Motion

Oscillations. Vern Lindberg. June 10, 2010

both double. A. T and v max B. T remains the same and v max doubles. both remain the same. C. T and v max

EXPERIMENT: MOMENT OF INERTIA

LAB 6 - GRAVITATIONAL AND PASSIVE FORCES

HOOKE S LAW AND SIMPLE HARMONIC MOTION

Applications of Second-Order Differential Equations

LAB 6: GRAVITATIONAL AND PASSIVE FORCES

Let s first see how precession works in quantitative detail. The system is illustrated below: ...

APPLIED MATHEMATICS ADVANCED LEVEL

Understanding Poles and Zeros

HOOKE S LAW AND OSCILLATIONS

Prelab Exercises: Hooke's Law and the Behavior of Springs

Sample Questions for the AP Physics 1 Exam

Sample lab procedure and report. The Simple Pendulum

Numerical Solution of Differential Equations

3.2 Sources, Sinks, Saddles, and Spirals

1 One Dimensional Horizontal Motion Position vs. time Velocity vs. time

USING MS EXCEL FOR DATA ANALYSIS AND SIMULATION

12.4 UNDRIVEN, PARALLEL RLC CIRCUIT*

Physics 40 Lab 1: Tests of Newton s Second Law

Aim : To study how the time period of a simple pendulum changes when its amplitude is changed.

Engineering Feasibility Study: Vehicle Shock Absorption System

Simple Harmonic Motion(SHM) Period and Frequency. Period and Frequency. Cosines and Sines

ACCELERATION DUE TO GRAVITY

Second Order Systems

19.7. Applications of Differential Equations. Introduction. Prerequisites. Learning Outcomes. Learning Style

PLOTTING DATA AND INTERPRETING GRAPHS

Oscillations: Mass on a Spring and Pendulums

= δx x + δy y. df ds = dx. ds y + xdy ds. Now multiply by ds to get the form of the equation in terms of differentials: df = y dx + x dy.

1.2 Second-order systems

Experiment: Static and Kinetic Friction

Worksheet 1. What You Need to Know About Motion Along the x-axis (Part 1)

Mathematical Modeling and Engineering Problem Solving

Numerical Methods for Differential Equations

Practice Test SHM with Answers

Freely Falling Bodies & Uniformly Accelerated Motion

Derivatives as Rates of Change

Physics 231 Lecture 15

2.6 The driven oscillator

Orbits of the Lennard-Jones Potential

Objectives. Materials

Appendix A: Science Practices for AP Physics 1 and 2

Ch 7 Kinetic Energy and Work. Question: 7 Problems: 3, 7, 11, 17, 23, 27, 35, 37, 41, 43

Lab 8: Ballistic Pendulum

Adequate Theory of Oscillator: A Prelude to Verification of Classical Mechanics Part 2

226 Chapter 15: OSCILLATIONS

Rotation: Moment of Inertia and Torque

The Bullet-Block Mystery

Lecture L22-2D Rigid Body Dynamics: Work and Energy

Computers in Science Education A new Way to teach Science?

Review of First- and Second-Order System Response 1

Journal of Engineering Science and Technology Review 2 (1) (2009) Lecture Note

Worksheet for Exploration 2.1: Compare Position vs. Time and Velocity vs. Time Graphs

Physics Labs with Computers, Vol. 2 P38: Conservation of Linear Momentum A

3.1 MAXIMUM, MINIMUM AND INFLECTION POINT & SKETCHING THE GRAPH. In Isaac Newton's day, one of the biggest problems was poor navigation at sea.

ACCELERATION OF HEAVY TRUCKS Woodrow M. Poplin, P.E.

State Newton's second law of motion for a particle, defining carefully each term used.

A Determination of g, the Acceleration Due to Gravity, from Newton's Laws of Motion

Differentiation of vectors

Unsteady Pressure Measurements

Physics 9e/Cutnell. correlated to the. College Board AP Physics 1 Course Objectives

correct-choice plot f(x) and draw an approximate tangent line at x = a and use geometry to estimate its slope comment The choices were:

Name Partners Date. Energy Diagrams I

Nonlinear Systems of Ordinary Differential Equations

Euler s Method and Functions

FRICTION, WORK, AND THE INCLINED PLANE

Solving ODEs in Matlab. BP205 M.Tremont

STATIC AND KINETIC FRICTION

Giant Slinky: Quantitative Exhibit Activity

1.(6pts) Find symmetric equations of the line L passing through the point (2, 5, 1) and perpendicular to the plane x + 3y z = 9.

Pre-lab Quiz/PHYS 224 Magnetic Force and Current Balance. Your name Lab section

Physics 211: Lab Oscillations. Simple Harmonic Motion.

ACCELERATION DUE TO GRAVITY

PHYS 2425 Engineering Physics I EXPERIMENT 9 SIMPLE HARMONIC MOTION

Physics 1120: Simple Harmonic Motion Solutions

ENERGYand WORK (PART I and II) 9-MAC

Determining the Acceleration Due to Gravity

AP Calculus BC 2006 Free-Response Questions

Chapter 4 One Dimensional Kinematics

ELASTIC FORCES and HOOKE S LAW

Homework 2 Solutions

FXA UNIT G484 Module Simple Harmonic Oscillations 11. frequency of the applied = natural frequency of the

Step response of an RLC series circuit

Lecture 8 : Dynamic Stability

Practice Exam Three Solutions

Notice numbers may change randomly in your assignments and you may have to recalculate solutions for your specific case.

Chapter 28 Fluid Dynamics

Chapter 3 Falling Objects and Projectile Motion

Transcription:

Runge-Kutta - Numerical Solutions of Differential Equations Kamalu J. Beamer March 21, 2013 1 Introduction As with all dynamical systems, it is interesting to observe the position and velocity of an object as functions of time. There are many approximations that can be made to obtain answers, some of which are more accurate than others. Different techniques were used to observe simple harmonic motion as a function of time. The first of which, the Euler s method, for evolving differential equations determines a velocity by taking the previous velocity, and extrapolating the slope of the that velocity (constant acceleration) for further determination of the next values in the function. The problem with the Eulers method, as will be seen, is that unless an unreasonably small step size (on the order of microseconds) is used, error quickly builds up and data is rendered useless. A much better approximation takes into account a change of this slope, and thus a non-constant acceleration that progresses forward in time. The 2nd order and 4th order Runge-Kutta methods will be studied in this lab. 2 Theory In its general form, consider the following differential equation where the right hand side is a function of both time and another function dependent on time. dy dt = f(t,y(t)) From this equation, the 2nd order Runge-Kutta method estimates y(t) as follows. k 1 = dt f(t,y(t)) k 2 = dt f(t+ dt k1 2,y(t)+ 2 ) y(t+dt) = y(t) + k 2 If we consider the simplest simple harmonic oscillator, a mass-on-a-spring, we get the following, coupled differential equations. 1

dx dt dv = v(t), dt = f(t) = -( k m ) x(t) By applying the 2nd order Runge-Kutta (RK2), we get the following two equations. x(t+dt) = x(t) + k 2, k 2 = dt (v(t) + (- k dt m ) x(t) 2 ) v(t+dt) = v(t) + k 2, k 2 = dt (- k dt m ) (x(t) + v(t) 2 ) The RK2 method produces more accurate data than Euler s method by calculating the slope at the midpoint of the interval based off of Euler s approximation. This midpoint slope is then used to make a better extrapolation of the endpoint of the interval. It is interesting to see how energy is conserved between the two methods. Obviously, a simple harmonic oscillator is a conservative system, therefore, we should not get an increase or decrease of energy throughout it s time-development. Table 1 includes a quantification of how well energy is conserved. The RK2 method is a significant improvement from Euler s method, however, we can get even better data with the 4th order Runge-Kutta technique. RK4 may not always produce more accurate data than RK2, but it is more stable, which becomes important with more complicated systems. The RK4 formulation is as follows. k 1 = dt f(t,y) k 2 = dt f(t+ dt 2,y(t)+k 1/2) k 3 = dt f(t+ dt 2,y(t)+k 2/2) k 4 = dt f(t+dt,y(t)+k 3 ) y(t+dt) = y(t) + 1 6 (k 1 + 2k 2 + 2k 3 + k 4 ) Both RK2 and RK4 methods were implemented into the code as functions. The unique thing about casting RK2 and RK4 as functions, is that a programmer can easily change the forces applicable to the problem by swapping out a single equation. Without these functions, a new piece of code must be produced for every type of force law. With a general form numerical approximation, a wide range of forces may be input; further, the values of these functions may be determined at small intervals. The RK2 and RK4 methods were applied to a pendulum, with both large and small amplitude oscillations. The pendulum follows the following mathematical equations. ml d2 θ dt 2 = -mgsin(θ) This standard equation can be identified in the general, coupled differential equations form as follows. 2

dθ dt = w; d2 θ dt 2 = dw dt = - g L sin(θ) This pendulum was observed with both small-amplitude and large-amplitude oscillations. The period of the oscillation was also studied as a function of initial pendulum angle. After an adequate code was produced, and accurate results were obtained, a more real-world situation was considered, one with drag. A linear drag force term (F drag = -bv). The pendulum was studied with underdamped, critically damped, and overdamped drag coefficients. 3 Data/Calculations Energy conservation is an extremely important law in the natural sciences. In order to properly simulate scientific models, conservation laws must be upheld. The following table displays the fractional error of different techniques used in this lab at different time intervals. dt (ms) Euler FracErr RK2 FracErr RK4 FracErr 1 0.0512721 1.25 E-8 2.49 E-14 10 0.848845 1.25 E-5 6.95 E-11 100 143.773 0.125783 6.94 E-6 300 1.779 E6 0.401906 1.67 E-3 Table 1 - Fractional errors for different numerical differential equation solutions as a function of step size. Referring to the following Figure 1, one can see why the Euler s method approximation is not an accurate assessment of a conservative system. Figure 1 displays the run away effect of energy. 3

Figure 1: Violation of the conservation of energy implies an inadequate piece of code. In the following figure, one can see the run away effect of energy in the Euler s method vs the conservation of energy of the RK2 method. Notice that within 3 periods, the Euler s method amplitude has tripled. 4

Figure 2: The position and velocity of the simple harmonic oscillator determined by two methods. As stated in Theory, the simple harmonic oscillator was converted into a simple pendulum that began it s motion at different angles. In order to ensure that the program was producing reasonable results, the position and velocity was plotted as a function of many different starting angles. Figures 3-10 display this behavior. 5

Figure 3: A pendulum whose initial angle was 0.0 radians. With no initial potential energy, the pendulum is static. Figure 4: A pendulum whose initial angle was 0.5 radians. With an initial 6

potential energy, the pendulum is no longer static; it behaves simple harmonic motion. Figure 5: A pendulum whose initial angle was 1.0 radians. 7

Figure 6: A pendulum whose initial angle was 1.5 radians. Figure 7: A pendulum whose initial angle was 2.0 radians. Figure 8: A pendulum whose initial angle was 2.5 radians. With a higher initial potential energy than the previous, the simple harmonic motion 8

displays a higher amplitude and slightly longer period than the last. Notice the slight bowing effect of the velocity. This is due to the gravitational force having an angular dependence. Figure 9: A pendulum whose initial angle was 2.9 radians. With a higher initial potential energy than the previous, the simple harmonic motion displays a higher amplitude and slightly longer period than the last. Notice an even larger bowing effect of the velocity. When the pendulum begins at an angle larger than 90 degrees, some of the gravitational force is negated by the normal force of the fixed rod holding the bob. This is why the bob accelerates less and thus has a lesser slope in certain parts of the graph. 9

Figure 10: A pendulum whose initial angle was π radians. With the highest gravitational potential energy, the bob is initially unaffected. This is because the rod supporting it is directly under it at the beginning of the simulation. This explains the seemingly flat velocity for the first 4 seconds of the simulation. In observing Figures 3-10, it is evident that the period changes as a function of initial angular position. This is contradictory to what is taught in basic mechanics course. This is because in basic mechanics courses, the sin(θ) = θ approximation is made. This approximation is only allowed if the angular displacement is small. Since significantly larger angular displacements were used, the period is no longer constant. Figure 11 displays oscillation period as a function of initial angle. 10

Figure 11: Notice the apparent exponential increase of oscillatory period as a function of initial angle. Note, apparent exponential increase because the last point on this graph is associated with a vertical pendulum bob and therefore, the next point would begin a new cycle of oscillatory period values. As mentioned in Theory, it is important to make simulations that abide by real physical rules, one of which is conservation of energy. The following figures, Figures 12-15 display the energies of different tehniques used in this lab. 11

Figure 12: The total energy of RK2 and RK4 methods with an initial bob angle of 1 radian. Note that although RK2 seems to run away, it only increases by 0.0014 units of energy over a span of 100 seconds. RK4 seems to not deviate at all, indicating an excellent differential equation solving code. 12

Figure 13: The total energy of RK2 and RK4 methods with an initial bob angle of 2.9 radians. Two things to note, the oscillatory behavior of the total energy of the RK2 method, albeit a total oscillation of 0.003 units of energy, and the stability of RK4. Again, the total energy fluctuations of RK4 cannot even be seen on this scale. It is also extremely valuable to look at the fractional error of the energies produced by the code. Figure 14: The fractional error of energy of RK2 and RK4 methods. The graph is done on a logscale to depict how miniscule the fractional error actually is. This graph is representative of an initial angular displacement of 1 radian. 13

Figure 15: The fractional error of energy of RK2 and RK4 methods, also on a logarithmic scale. This graph is representative of an initial angular displacement of 2.9 radians. The final phenomenon observed in this lab was the addition of drag forces to the pendulum. As is known from study of classical mechanics, a harmonic oscillator can be damped in three ways; an oscillator may be underdamped, overdamped or critically damped. The following figure, Figure 16 displays all three cases. Referring to the drag force equation above, b underdamped = 0.05 kg s, b overdamped = 10.0 kg s, and b criticallydamped = 2.0 kg s. 14

Figure 16: An excellent depiction of a single harmonic oscillator undergoing different damping constants. 4 Conclusion There are a few different approaches to solving coupled differential equations; a few of which are better than others. This lab was an excellent exploration of the different techniques available to computer programmers. It was determined that the 4th order Runge-Kutta technique was the best of those used in this lab. I am sure there are other, even more accurate approximations to differential equations. These techniques will prove to be extremely valuable in future programming endeavors. Another valuable sub-lesson in this lab was the use of functions. Properly defining and pointing to functions may save lines of spaghetti code and will prove extremely important for code efficiency. 5 References 1. Gorham, Peter. DiffEq1. DiffEq1. N.p., n.d. Web. 21 Mar. 2013. <http://www.phys.hawaii.edu/ gorham/p305/diffeq1.html>. 2. Gorham, Peter. DiffEq2. DiffEq2. N.p., n.d. Web. 21 Mar. 2013. <http://www.phys.hawaii.edu/ gorham/p305/diffeq2.html>. 15

3. RungeKutta Methods. Wikipedia. Wikimedia Foundation, 03 Aug. 2013. Web. 21 Mar. 2013. <http://en.wikipedia.org/wiki/rungekutta-methods>. 16