Download presentation

Presentation is loading. Please wait.

Published byLilliana Orms Modified about 1 year ago

1
Developing Computer Simulations Using Object Oriented Programming. The Three Body Problem: A Case Study Mike O’Leary & Shiva Azadegan Towson University Supported by the National Science Foundation under grant DUE

2
What is the Course? We teach an interdisciplinary course in modeling, numerical methods, and computer programming. Mixed audience primarily of computer science and mathematics majors. Prerequisites: –Calculus 1, Calculus 2 –Introduction to Computer Science 1 (C++)

3
The Goal To teach students how to take a realistic problem –Model it –Choose an appropriate numerical method –Implement that method using modern object- oriented programming and using modern computer graphics –Interpret the results –Write a report summarizing their investigation

4
Methodology Team taught –One mathematics & one computer science instructor Course is driven by a sequence of three realistic project problems –Each project requires modeling, numerical methods, programming, and a report –Students are evaluated based on their report and on their program.

5
The Problems Realistic problems from the sciences Examples: –Three body problem –Heat flow –Motion under air resistance –Spread of HIV virus through the body –Traffic flow

6
Numerical Methods Evaluating integrals –Trapezoidal Rule, Simpson’s Rule Ordinary differential equations and systems –Euler’s method, Implicit Euler, Heun’s method, Runge-Kutta methods, Runge-Kutta-Fehberg methods –Error analysis and control Partial differential equations. –Finite difference methods –Error and stability analysis using von Neumann methods

7
Programming C++ Microsoft Visual Studio Microsoft Foundation Classes (MFC)

8
Object–Oriented Programming Extensive use of classes –What is a class? A structure containing data and methods for manipulating the data Examples: dialog, simulation, graph, vector –How are they useful? Organization Encapsulation (Data Hiding) Inheritance Reusability

9
Student Example

10
Event-Driven Programming Program initializes, then waits for events –Button is pressed –Key is pressed –Mouse is moved When an event occurs, a certain piece of code is executed

11
Student Example

12
Programming: Graphics Full use is made of the computer’s ability to represent information graphically Use the MFC library of Microsoft Visual C++ to access graphics routines –In common use Student example

13
Implementation How can such a course be taught in practice? What are the details?!

14
How is it Taught? Team taught Mathematics and computer science are closely integrated. Ideas are introduced in the order that they are needed.

15
Worksheets Because no text is available for the course, we provide students with a sequence of worksheets. These summarize the material taught in class and contain exercises. Examples

16
Worksheet 1 Mathematics –Trapezoidal Rule –Simpson’s Rule Programming –Review of functions –Function prototypes –Passing functions Assignment –Write a console program to implement Trapezoidal Rule & Simpson’s Rule –Implement and analyze Simpson’s 3/8 Rule

17
Worksheet 2 Programming –Classes, objects & instances –Private & public data & methods –Constructors & destructors; setters & getters –Overloading Assignment –Create a class for points, vectors, and line segments. –Use inheritance.

18
Worksheet 3 Programming –Classes, continued –Pointers to functions Assignment –Write a program with a class called Integral. –It should have a public method that take as input the number of subintervals and return the trapezoidal rule approximation of the integral. –It should have another method that return’s the Simpson’s rule approximation

19
Worksheet 3 Results

20
Worksheet 3 Results

21
Worksheet 4 Programming –Introduction to dialog-based programming –Introduction to event-driven programming Assignment –Write a dialog-based version of the integral program

22
Worksheet 4 Results

23
Worksheet 5 Programming –Create a dialog based program with graphics. –Classes for balls, for control dialog and for graphics dialog.

24
Worksheet 6 Modeling –Newton’s law of gravity. –Model for the three body problem where for i = 1, 2, 3. –12 equations in 12 variables plus time

25
Worksheet 6 Mathematics –Euler’s method –Implicit Euler –Heun’s method (Improved Euler) Applications to single equations Assignment –Write a dialog based program to solve a particular initial-value problem.

26
Worksheet 6 Results

27
Worksheet 7 Mathematics –Fourth order Runge-Kutta method –Applications to systems of differential equations Assignment –Modify the previous program to also implement the Runge-Kutta method –Write a program that solves a system using the Runge-Kutta method

28
Worksheet 7 Results

29
Project Write a C++ program that simulates the motion of three bodies under the influence of gravity As input the program should take the initial positions, velocities, and masses of all of the bodies, as well as the gravitational constant, the time step, and the ending time.

30
Project The program should use a Runge-Kutta method to calculate the resulting motion of the bodies. The program should graphically display the results.

31
Project You are then to write up a technical report that answers the following questions: 1.What is the mathematical model of the problem? 2.What is the numerical method used to solve the problem? 3.What is the structure of your program? 4.Describe the range of possible behaviors shown by the system.

32
Project In particular, for question 4, consider the following questions: –Is it possible for the system to eject one of the bodies to infinity? –Is it possible for the system to return to its initial state? –Is it possible for the system to return to a state close to, but not the same as its initial state?

33
Results Student programStudent program Student code

34
Where did we go from here? Double pendulum Heat flow

35
Double pendulum Model Mathematics –Lagrangian dynamics –Calculus of variations Programming –Use of the mouse

36
Double pendulum Results –Sample programSample program –Sample codeSample code

37
Heat equation Model –As a system of ordinary differential equations –Probabilistically –As a partial differential equation Mathematics –Finite difference methods –Implicit and explicit –Von Neumann analysis of stability Programming –Menus

38
Heat equation Results –Student programStudent program –Student codeStudent code

39
Other projects Motion of a baseball under air resistance Wave motion Traffic jam formation Double spring Resonant filter (http://www.cs/gasou.edu/faculty/demos/filterdemo/)Resonant filterhttp://www.cs/gasou.edu/faculty/demos/filterdemo/ Dynamics of HIV

40
Evaluation & Lessons What did we learn?

41
Project Due Dates Same due date for program and report –Students would not finish the program until the due date. –Student report quality suffered. Now we have two due dates –One for the program –One for the report. –These are graded separately

42
Open Ended Questions Originally we used open-ended questions for the project reports –Without focus, students had difficulty deciding what was important Now we ask the students detailed and specific questions which they must answer in their report

43
Student reaction Positive reaction –Students enjoyed the way the programming and the mathematics were integrated –Students also enjoyed working on problems with a purpose Negative reaction –Math students have difficulty with the programming, and computer science students have difficulty with the mathematics –Encourage teamwork!

44
Resources

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google