This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Chapter 1 From Formula to Program 1.1 Surface Area Increase Just Plug It In 1.2 Minimum of a Quadratic on an Interval Check and Evaluate We grow up in mathematics playing with formulas. The simplicity of plugging in and letting the formula do the work is appealing. After all, it is cool to take something that is hard (like problem solving) and reduce it to something that is easy (like evaluation). Nevertheless there are skills to acquire, e.g., when to use A = r 2 instead of C = 2 r , how to derive r = A/ , understanding why 22/7 is sometimes a good enough approximation to , etc. The situation is similar with computer programming. An algorithm is a for mula and the act of writing a program is the act of describing its steps in such a way that the computer can carry them out. What takes us beyond the world of simple math book recipes is complexity and length. The logic behind a computer program, even a very short one, is typically more intricate than what we encounter in elemen tary mathematics. Reasoning about a computer program whose evaluation involves a billion steps is very di f erent than checking over the arithmetic associated with F = (9 / 5) C + 32. We clearly need to expand our problemsolving skill set if we are to write and use computer programs. A good way to begin is to practice the conversion of simple mathematical formulae into a computer programs. The three examples that make up this chapter each have a message. We f rst develop a program that computes how much the surface area of a sphere increases if the radius increases a small amount. We discover that di f erent evaluation strategies can lead to di f erent computed results. We then consider the problem of f nding the minimum value of a quadratic on an interval. The formula to be used depends on whether the quadratics turning point is inside the interval or beyond its endpoints. 1 2 Chapter 1. From Formula to Program 1.1 Surface Area Increase Problem Statement The surface area of a sphere having radius r is given by A ( r ) = 4 r 2 . How much does the surface area of a sphere increase when its radius is increased by a tiny amount? Write a script that solicits the sphere radius r (in kilometers), the increase amount r (in millimeters), and then displays the surface area increase (in square meters). What is the increase when the radius of a spherical Earth ( r = 6367km) is increased by a few millimeters? Program Development If we literally transcribe the increase formula A = 4 ( r + r ) 2 4 r 2 into Matlab , then we obtain delta_A = (4*pi*(r+delta_r)^2)  (4*pi*r^2) On the other hand, with a little algebra we discover that A = 4 r (2 + r ) leading to delta_A = 4*pi*(2*r + delta_r)*delta_r If we wish to explore the situation where r << r , then it is interesting to see how the approximation A 8 r r behaves, i.e., delta_A = 8*pi*r*delta_r With respect to the inputting of trial values, a pair of...
View
Full
Document
This note was uploaded on 04/30/2008 for the course CS 100 taught by Professor Fan/vanloan during the Spring '07 term at Cornell University (Engineering School).
 Spring '07
 FAN/VANLOAN

Click to edit the document details