# lectode - Chapter 11 Coding Numerical Integration of ODEs...

This preview shows pages 1–4. Sign up to view the full content.

Chapter 11 Coding & Numerical Integration of ODEs 11.1 Introduction Translating algorithms into code takes art, patience, and hard work. The process can be greatly shortened by following a few rules to implement the algorithm. The sources of the algorithm are not of concern here although in practice we should be familiar with the intent and limitations of any algorithm, particularly when it relates to numerical computations. We will leave these issues for later as we are mainly concerned with programming. 11.2 Rules of thumbs This section lists a few rules of thumbs to improve the coding of algorithms, and help in the homework problem. 11.2.1 DeFne the problem Understand what is required in the computations, deFne the input, the output and the computations to be performed. Making sure the problem is well-deFned goes a long way in determining what kind of input data and what sort of output is required. 11.2.2 Divide and conquer Dividing the problem into functionally separate tasks helps in making large cod- ing projects manageable. Identify the repetitive tasks and consider isolating them into well-designed subroutines and functions. This subdivision is critical for the remainder of the programming tasks as it: divides into manageable units, allows 69

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
70 CHAPTER 11. CODING & NUMERICAL INTEGRATION OF ODES validation to proceed in stages, and simplify code reuse. The details of the compu- tations will then be boxed into compartments and a higher level abstraction about the algorithm is then possible. Most numerical tasks follow the plan: 1. data input 2. perform computations 3. output results Each of these tasks may contain a long list of substasks but the divide and conquer strategy can be applied to those recursively. 11.2.3 Use top-down design Start designing the problem from the top starting with the main program and Flling in the subroutine as you go. This will help you clarify the ±ow of the code to yourself. Write shell routines in the initial go and start Flling them and validating them in groups. Postpone the details of each routine as long as possible. 11.2.4 Use pseudo-code Describe in pseudo code (i.e. programming language independent) the steps needed in the algorithms. 11.2.5 Decide on optimal data structure In most numerical computations this will simply arrays as they are the most e²- cient data structures for many types of computations. 11.2.6 Conceptual simplicity Avoid using obfuscated code even though it may seem great at the moment. Ob- fuscated code can be hard to read, and even the implementors would have a hard time remembering what it does 3 months after they coded it. 11.2.7 Validation It is important to gain assurances that parts of the code are working properly in order to catch coding and (more ominously) algorithmic mistakes. It is then imperative that subroutines are validated as one is developing the code. If an error is introduced later it will useful to restrict its tracking to the untested portions of the code. Validation can take many forms:
11.3. ORDINARY DIFFERENTIAL EQUATIONS 71 1. Run a problem with a known (trivial) answer and see if your code replicates

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/08/2012 for the course MSC 321 taught by Professor Staff during the Fall '08 term at University of Miami.

### Page1 / 11

lectode - Chapter 11 Coding Numerical Integration of ODEs...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online