# Algorithmic Modeling

 Ninety-eight percent of the thrill comes from knowing that the thing you designed works, and works almost the way you expected it would. If that happens, part of you is in that machine. Tracy Kidder, The Soul of a New Machine. New York: Avon Books, 1981.

In addition to representing data in digital form, the computer also represents processes in digital form. The computer represents these processes as algorithms. An algorithm is set of carefully defined instructions that take a set of inputs, manipulate them, and produce some output. A recipe is an informal example of this. It takes a set of inputs, called ingredients, manipulates them in specific ways, and produces a (usually!) edible output. Algorithms can include simple sequences of instructions, or instructions that involve decision points or iteration. More information on algorithms can be found at Wikipedia.

A computer programmer encodes algorithms in software using programming
languages. These languages are designed to specify instructions using three basic elements:

• Sequence—executing instructions one at a time, in order
• Selection—choosing which instructions to execute based on some condition
• Iteration—repeating instructions until some condition obtains

A simple example would be a program to compute the amount of interest to credit for savings accounts at a bank. Such a program must use information on the account balance, the interest rate, and the period of time over which the interest should be computed. This program could be written into a single sequence of statements such as

float balance, interestRate, term, interest;
balance = 1000.00;
interestRate = .05;
time = 1.0;
interest = balance * interestRate * time;

This program is written in the Java programming language. The first statement tells the computer that all three numbers have decimal points; the next three statements set values for the variables balance, interestRate, and time; and the last line calculates the interest. Note how similar the last line is to the original formula.

A more complicated example would be software to manage the flight of an aircraft, which must account for wind speed, the weight of the plane, the position of the various flight surfaces on the wings and tail, and so forth. This sort of program would have an algorithm that iterates (repeats) forever, constantly checking the current speed of the aircraft and adjusting as necessary:

Loop forever
{   If speed is too fast
slow down
Else if speed is too slow
speed up   }

This example shows the use of iteration (a loop) and selection (the "if" statements).

All programs, regardless of how simple or complicated they are, make use of the three basic control structures. How well a program works depends on how carefully the algorithms are designed and how accurately it models physical reality.

The programmer must make wise choices when deciding what to include or exclude from the software model of the world. In order to produce the most accurate model, the programmer would have to include virtually every detail related to the plane, from the color of the paint on the wings to the smell of the sweater of the passenger in seat 4B. Obviously, including everything is impractical, so one must judiciously choose those variables that have a significant effect on the answer being sought (such as how much fuel is required to get from Detroit, Michigan, to Paris, France).

These pages were written by Steven H. VanderLeest and Jeffrey Nyhoff and edited by Nancy Zylstra