Foundation Chap1 - Chapter 1 From Formula to Program 1.1...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 1 From Formula to Program § 1.1 Just Plug It In Surface Area Increase § 1.2 Check and Evaluate Minimum of a Quadratic on an Interval § 1.3 Recursive Formulae* Fibonacci Numbers and the Golden Ratio 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 ,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 formula 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 elementary mathematics. Reasoning about a computer program whose evaluation involves a billion steps is very different than checking over the arithmetic associated with F =(9 / 5) C +32. We clearly need to expand our problem-solving 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 Frst develop a program that computes how much the surface area of a sphere increases if the radius increases a small amount. We discover that different evaluation strategies can lead to different computed results. We then consider the problem of Fnding the minimum value of a quadratic on an interval. The “formula” to be used depends on whether the quadratic’s “turning point” is inside the interval or beyond its endpoints. The last example involves a formula for computing what is called the ±ibonacci sequence. The recipe that we use to compute the “next” ±ibonacci number f n +1 assumes that we have computed its predecessors f n and f n - 1 . It is not a matter of plugging the value of n into an expression. The ±ibonacci numbers are deFned in terms of themselves, i.e., recursively. 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Example 1.1 Surface Area Increase % Script Eg1_1 % Surface Area Increase r = input(’Enter radius (kilometers):’); delta_r = input(’Enter increase (millimeters):’); clc disp(sprintf(’Sphere radius = %12.6f kilometers’,r)) disp(sprintf(’Radius increase = %12.6f millimeters’,delta_r)) disp(’ ’) disp(’Surface Area Increase:’) delta_r = delta_r/10^6; % Method 1 delta_A = (4*pi*(r + delta_r)^2 - 4*pi*r^2)*10^6; disp(sprintf(’ Method 1: %15.6f square meters’,delta_A)) % Method 2 delta_A = (4*pi*(2*r + delta_r)*delta_r)*10^6; disp(sprintf(’ Method 2: %15.6f square meters’,delta_A)) % Method 3 delta_A = (8*pi*r*delta_r)*10^6; disp(sprintf(’ Method 3: %15.6f square meters’,delta_A)) Sample Output: Sphere radius = 6367.000000 kilometers Radius increase = 1.234000 millimeters
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

Foundation Chap1 - Chapter 1 From Formula to Program 1.1...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online