Lecture 3 Notes

The loop body n 10 number of data values total 0

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: . end 1/30/14 37 1/30/14 Mo=va=ng Problem: Compu=ng Square Roots 38 A Geometric Restatement Given a posi=ve number A, find its square root. Given a posi=ve number A, find a square whose area is A. 1/30/14 39 1/30/14 40 Observa=on An Ini=al Guess W=1 L=A s How can we make this rectangle “ more square”? 1/30/14 The answer is in between L and W: W<s<L 41 1/30/14 42 1/31/14 Idea: Repeat: W W1 L L1 = (L+W)/2 L1 W1 = A/L1 L2 = (L1+W1)/2 W2 = A/L2 W1 L1 1/30/14 43 1/30/14 44 A Script A Modified Script A = input(‘A:’); L0 = A; W0 = A/L0; L1 L2 L3 L4 = = = = (L0 (L1 (L2 (L3 + + + + W0)/2; W1)/2; W2)/2; W3)/2; A = input(‘A:’); L = A; W = A/L; W1 W2 W3 W4 = = = = A/L1; A/L2; A/L3; A/L4; 1/30/14 L L L L 45 = = = = (L (L (L (L W W W W = = = = A/L; A/L; A/L; A/L; 46 More General A = input(‘A:’); L = A; W = A/L; 1/30/14 W)/2; W)/2; W)/2; W)/2; 1/30/14 Square Root with I...
View Full Document

This document was uploaded on 03/11/2014 for the course CSCI 004 at Brown.

Ask a homework question - tutors are online