developing simulations and demonstrations using microsoft visual c++ mike o’leary shiva azadegan...

31
Developing Simulations Developing Simulations and Demonstrations and Demonstrations Using Microsoft Visual Using Microsoft Visual C++ C++ Mike O’Leary Mike O’Leary Shiva Azadegan Shiva Azadegan Towson University Towson University Supported by the National Science Foundation under grant DUE 9952625

Upload: rosaline-watts

Post on 11-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

Developing Simulations and Developing Simulations and Demonstrations Using Demonstrations Using Microsoft Visual C++Microsoft Visual C++

Mike O’LearyMike O’Leary

Shiva AzadeganShiva Azadegan

Towson UniversityTowson University

Supported by the National Science Foundation under grant DUE 9952625

Page 2: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

IntroductionIntroduction

We have developed a course in Scientific We have developed a course in Scientific Modeling and SimulationModeling and Simulation

Page 3: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

What is the Course?What is the Course?

This is a one-semester interdisciplinary course This is a one-semester interdisciplinary course straddling the boundaries between mathematical straddling the boundaries between mathematical modeling, numerical methods, and modern modeling, numerical methods, and modern object-oriented computer programming. object-oriented computer programming.

Our course is project-driven.Our course is project-driven. Given a realistic problem, weGiven a realistic problem, we

Create a model, Create a model, discuss appropriate numerical methods, and then discuss appropriate numerical methods, and then create a simulation of the problem using Microsoft create a simulation of the problem using Microsoft

Visual C++ that takes full advantage of our Visual C++ that takes full advantage of our computer's graphical capabilities.computer's graphical capabilities.

Page 4: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation
Page 5: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

Course ObjectivesCourse Objectives The students upon completing these courses will have:The students upon completing these courses will have:

the knowledge to choose proper numerical methods to solve a the knowledge to choose proper numerical methods to solve a scientific problem;scientific problem;

the knowledge of modeling techniques to develop a model for the knowledge of modeling techniques to develop a model for the problem;the problem;

the programming skills to implement the model using an object-the programming skills to implement the model using an object-oriented programming language;oriented programming language;

the critical thinking skill to form conclusion based upon the the critical thinking skill to form conclusion based upon the results;results;

the communication and writing skills to prepare and present the communication and writing skills to prepare and present technical reports;technical reports;

the experience of working in teams with their peers from different the experience of working in teams with their peers from different disciplines on multidisciplinary problems.disciplines on multidisciplinary problems.

Page 6: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

What are the Prerequisites?What are the Prerequisites?

Calculus 1, Calculus 2 Calculus 1, Calculus 2 Introduction to Programming 1 Introduction to Programming 1

Page 7: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

How does the Course Proceed?How does the Course Proceed?

The course is driven by the projects.The course is driven by the projects. The modeling, numerical methods, and The modeling, numerical methods, and

computer programming are introduced as computer programming are introduced as needed for the solution of a particular problem.needed for the solution of a particular problem.

Course can be split into four large portionsCourse can be split into four large portions IntroductionIntroduction First projectFirst project Second projectSecond project Third project Third project

Page 8: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

IntroductionIntroduction

Introduction to programming with MFC & Introduction to programming with MFC & dialog based programming.dialog based programming.

Review of numerical methods for Review of numerical methods for integration.integration.

Write some programs that evaluate Write some programs that evaluate integrals.integrals.

Review of classes.Review of classes. Introduction to numerical methods for Introduction to numerical methods for

differential equations.differential equations.

Page 9: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation
Page 10: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation
Page 11: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

First ProjectFirst Project

Involves solving a system of differential Involves solving a system of differential equations.equations.

May or may not require the use of graphics.May or may not require the use of graphics. Introduction to graphics.Introduction to graphics. Dynamic memory allocationDynamic memory allocation Allows more sophisticated graphics- e.g. graphs Allows more sophisticated graphics- e.g. graphs

of functions.of functions. This is more sophisticated programming This is more sophisticated programming

concept.concept.

Page 12: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

Second ProjectSecond Project Also a system of differential equations.Also a system of differential equations. More sophisticated mathematicsMore sophisticated mathematics Either a more sophisticated model: e.g. calculus Either a more sophisticated model: e.g. calculus

of variationsof variations or better numerical methods: e.g. adaptive or better numerical methods: e.g. adaptive

methodsmethods More sophisticated programmingMore sophisticated programming Function graphsFunction graphs Multiple graphsMultiple graphs Scrolling & slidersScrolling & sliders

Page 13: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

Third ProjectThird Project

Partial differential equationsPartial differential equationsModelingModelingAnalysis of numerical methodsAnalysis of numerical methodsMore sophisticated programmingMore sophisticated programmingThe mouseThe mouseTimersTimers

Page 14: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

What are the Assignments?What are the Assignments?

Each project takes students 2-4 weeks to Each project takes students 2-4 weeks to complete.complete.

Students complete a written project report Students complete a written project report 10-30 pages10-30 pages Describes in detail the model, the numerical methods, Describes in detail the model, the numerical methods,

and the program used to solve the problem.and the program used to solve the problem. Gives a complete answer to the assigned project Gives a complete answer to the assigned project

questions.questions. Students programs are also graded.Students programs are also graded. It is important that the paper and the program It is important that the paper and the program

have different due dates!have different due dates!

Page 15: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

What have we developed?What have we developed?

Lecture notes for the entire coursesLecture notes for the entire courses Not all of the material was used each semester, so Not all of the material was used each semester, so

there is more than can be covered in one semester.there is more than can be covered in one semester.

Projects that were assigned. Projects that were assigned. 8 Projects are given; we only would use 3 in a single 8 Projects are given; we only would use 3 in a single

semester.semester.

Sample codeSample code CD contains source code for the examples described CD contains source code for the examples described

in the notes.in the notes.

Page 16: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

Chapter 12: Adaptive Methods for Differential Equations

Chapter 1: Dialog Based ProgrammingChapter 2: Introduction to Numerical MethodsChapter 3: Classes and Software DesignChapter 4: Differential Equations

Chapter 5: Project- The Baseball Problem

Chapter 6: Graphics

Chapter 7: Project- The Three Body ProblemChapter 8: Project- The Double Spring

Chapter 9: Sliders & Scrolling

Chapter 10: Dynamic Memory Allocation

Chapter 13: Project- Dynamics of HIVChapter 14: Project- The Double Pendulum

Chapter 11: Project- The Resonant Filter

Chapter 15: The Mouse

Chapter 16: Project- DiffusionChapter 18: Project- Waves

Chapter 17: Timers

Page 17: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

What are the Projects?What are the Projects?

Page 18: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

Motion of a baseball under air Motion of a baseball under air resistance. resistance.

What is the optimal angle to hit a baseball What is the optimal angle to hit a baseball so that it travels the farthest? Does this so that it travels the farthest? Does this angle change with the velocity of the ball?angle change with the velocity of the ball?

Students write a program that gives the Students write a program that gives the total distance the ball will travel.total distance the ball will travel.

This project does not require a graphical This project does not require a graphical component, but one can be incorporated.component, but one can be incorporated.

Page 19: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation
Page 20: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

The three body problemThe three body problem

Determine the motion of three (or more) Determine the motion of three (or more) bodies in the plane under the influence of bodies in the plane under the influence of gravity.gravity.

Students are asked to find roughly periodic Students are asked to find roughly periodic orbits.orbits.

Page 21: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation
Page 22: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

The double springThe double spring Describe the motion of a mass attached to two Describe the motion of a mass attached to two

springs in the plane.springs in the plane. Project questions include:Project questions include:

Given initial conditions, determine the location of the Given initial conditions, determine the location of the mass after a period of time, and estimate the mass after a period of time, and estimate the accuracy of the answer.accuracy of the answer.

Are there solutions that remain above the line Are there solutions that remain above the line connecting the two fixed points for all time?connecting the two fixed points for all time?

Analyze the stability properties of the system. Does it Analyze the stability properties of the system. Does it display sensitive dependence on initial conditions?display sensitive dependence on initial conditions?

Prove that the sum of the kinetic energy and the Prove that the sum of the kinetic energy and the energy stored in the springs is conserved.energy stored in the springs is conserved.

Page 23: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation
Page 24: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

The resonant filterThe resonant filter Create a model of an LRC resonant filter.Create a model of an LRC resonant filter. Project questions:Project questions:

Given a class that contains an unknown input signal known to be Given a class that contains an unknown input signal known to be the sum of sinusoids, find the frequency of the unknown signal.the sum of sinusoids, find the frequency of the unknown signal.

This requires an analysis of the preferred frequency of This requires an analysis of the preferred frequency of the solutions to a constant coefficient second order the solutions to a constant coefficient second order differential equation.differential equation.

Programming notesProgramming notes The interface is best built with slider controls.The interface is best built with slider controls. Because this requires displaying a graph of a function, some Because this requires displaying a graph of a function, some

more complex graphical programming is needed. more complex graphical programming is needed. Almost requires the use of dynamically created arrays.Almost requires the use of dynamically created arrays.

Page 25: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

Dynamics of HIVDynamics of HIV Create a simple one-compartment model for HIV Create a simple one-compartment model for HIV

infection of CD4+ T-cells.infection of CD4+ T-cells. Obtain three equations in three variables.Obtain three equations in three variables. Investigate the effect of an RT-inhibitor. Though they do Investigate the effect of an RT-inhibitor. Though they do

not kill HIV, they prevent HIV cells from infecting healthy not kill HIV, they prevent HIV cells from infecting healthy cells.cells.

Project questionsProject questions Show that that the system tends to a steady state.Show that that the system tends to a steady state. Show that, if the RT inhibitor is sufficiently effective, then HIV will Show that, if the RT inhibitor is sufficiently effective, then HIV will

be entirely removed from the body.be entirely removed from the body. Show that, there is a lower threshold for effectiveness of the RT Show that, there is a lower threshold for effectiveness of the RT

inhibitor which, though it would not eliminate the virus, it would inhibitor which, though it would not eliminate the virus, it would prevent the onset of AIDS.prevent the onset of AIDS.

Compare the numerical results with their analytic counterparts.Compare the numerical results with their analytic counterparts.

Page 26: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation
Page 27: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

The double pendulumThe double pendulum

Create a model for a jointed pendulum.Create a model for a jointed pendulum.Best technique requires variational Best technique requires variational

methods.methods.Project questionsProject questions

Does the double pendulum display sensitive Does the double pendulum display sensitive dependence on initial conditions?dependence on initial conditions?

Page 28: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation
Page 29: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

DiffusionDiffusion Create a model for diffusion processes.Create a model for diffusion processes. Three different methods to create the model-Three different methods to create the model-

System of ordinary differential equationsSystem of ordinary differential equations Directly, as a partial differential equationDirectly, as a partial differential equation Probabilistic methods.Probabilistic methods.

Introduce finite difference methods for solving partial differential Introduce finite difference methods for solving partial differential equationsequations Discuss consistency, stability and convergence. Discuss consistency, stability and convergence.

Project question to simulate the temperature of a solid bar.Project question to simulate the temperature of a solid bar. Because the exact value can be found using Fourier series techniques, Because the exact value can be found using Fourier series techniques,

one can compare the students solution to the actual result for grading.one can compare the students solution to the actual result for grading. Programming note: the best way to enter the initial data is to use the Programming note: the best way to enter the initial data is to use the

mouse.mouse.

Page 30: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation
Page 31: Developing Simulations and Demonstrations Using Microsoft Visual C++ Mike O’Leary Shiva Azadegan Towson University Supported by the National Science Foundation

Wave MotionWave Motion

Create a model of wave motion. Create a model of wave motion. Can be done as a system of ordinary differential Can be done as a system of ordinary differential

equations, or directly as a partial differential equations, or directly as a partial differential equation.equation.

Introduce finite difference methods for the Introduce finite difference methods for the solution.solution.

Project question is to simulate the motion of a Project question is to simulate the motion of a vibrating string.vibrating string.

Students verify that the wave speed is correctly Students verify that the wave speed is correctly calculated.calculated.