Numerical Methods or Two Recipes for Pi CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.

Slides:



Advertisements
Similar presentations
Chapter 5 Mathematics of Finance.
Advertisements

Art Foundations Exam 1.What are the Elements of Art? List & write a COMPLETE definition; you may supplement your written definition with Illustrations.
Slide 1 Insert your own content. Slide 2 Insert your own content.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
Factors, Primes & Composite Numbers
Combining Like Terms. Only combine terms that are exactly the same!! Whats the same mean? –If numbers have a variable, then you can combine only ones.
Chapter 3: Top-Down Design with Functions Problem Solving & Program Design in C Sixth Edition By Jeri R. Hanly & Elliot B. Koffman.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Copyright © 2010 Pearson Education, Inc. Slide
0 - 0.
How To Multiply Fractions
2 pt 3 pt 4 pt 5pt 1 pt 2 pt 3 pt 4 pt 5 pt 1 pt 2pt 3 pt 4pt 5 pt 1pt 2pt 3 pt 4 pt 5 pt 1 pt 2 pt 3 pt 4pt 5 pt 1pt Simplify All mixed up Misc. AddingSubtract.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
CS4026 Formal Models of Computation Running Haskell Programs – power.
SADC Course in Statistics Estimating population characteristics with simple random sampling (Session 06)
1 Reverse a Journal Find an existing journal and reverse it in either: A original period B a different period.
STATISTICAL INFERENCE ABOUT MEANS AND PROPORTIONS WITH TWO POPULATIONS
PLAN Interpretive Visuals 9/2009 Interpretive Visuals.
Lecture 07 – Iterating through a list of numbers.
Chapter ChEn 4253 Terry A. Ring
Simple Interest Lesson
O X Click on Number next to person for a question.
5.9 + = 10 a)3.6 b)4.1 c)5.3 Question 1: Good Answer!! Well Done!! = 10 Question 1:
Linking Verb? Action Verb or. Question 1 Define the term: action verb.
Squares and Square Root WALK. Solve each problem REVIEW:
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
Limits (Algebraic) Calculus Fall, What can we do with limits?
Why Take EXPLORE? EXPLORE shows your strengths and weaknesses in English, mathematics, reading, and science. EXPLORE helps you search for careers and.
1 First EMRAS II Technical Meeting IAEA Headquarters, Vienna, 19–23 January 2009.
Virginia Birch MFNERC Numeracy Specialist
Addition 1’s to 20.
25 seconds left…...
Test B, 100 Subtraction Facts
Doubles Facts Doubles with Pictures Doubles without Pictures Pictures Only.
11 = This is the fact family. You say: 8+3=11 and 3+8=11
Week 1.
The Right Questions about Statistics: How hypothesis testing works Maths Learning Centre The University of Adelaide A hypothesis test is designed to DECIDE.
We will resume in: 25 Minutes.
Solving Addition and Subtraction Inequalities
Bottoms Up Factoring. Start with the X-box 3-9 Product Sum
Chapters: Prologue, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 Prologue (History of Oceanography) Marine Geography Homework Chapters: Prologue,
1 Unit 1 Kinematics Chapter 1 Day
FIND THE AREA ( ROUND TO THE NEAREST TENTHS) 2.7 in 15 in in.
O X Click on Number next to person for a question.
Chapter 16: Correlation.
K-MEANS ALGORITHM Jelena Vukovic 53/07
Investments, 8 th edition Bodie, Kane and Marcus Slides by Susan Hine McGraw-Hill/Irwin Copyright © 2009 by The McGraw-Hill Companies, Inc. All rights.
Excerpt from a WallStreet Journal article: 6. Yet another Dell customer called to complain that his keyboard no longer worked. He had cleaned it by filling.
- Erik Spiller and Keon Massey The Concept of Chess.
Exponential Functions en-GB&v=AmFMJC45f1Q.
L.E.Q. How do you use segment and area models to find the probabilities of events?
The King, the servant, and the conundrum. Once upon a time in a land not so far from here there lived a king…… He had a loyal servant who would advise.
Computing with Strings CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
Animation CSC 161: The Art of Programming Prof. Henry Kautz 10/14/2009.
Computing with Numbers CSC 161: The Art of Programming Prof. Henry Kautz 9/14/2009.
Python Programming in Context Chapter 2. Objectives To understand how computers can help solve real problems To further explore numeric expressions, variables,
60 Questions (review for final exam) CSC 161: The Art of Programming Prof. Henry Kautz 12/7/
Monte Carlo Methods Versatile methods for analyzing the behavior of some activity, plan or process that involves uncertainty.
Chapter 1.6 Probability Objective: Students set up probability equations appropriately.
If..else Use random numbers to compute an approximation of pi Simulation of a special game of darts Randomly place darts on the board pi can be computed.
COMPUTERS SIMULATION IN MATHEMATICS EDUCATION Dr. Ronit Hoffmann Kibbutzim College of Education, Israel.
Chapter 7 Lesson 8 Objective: To use segment and area models to find the probabilities of events.
Random numbers What does it mean for a number to be random?
Random numbers What does it mean for a number to be random?
Day 91 – Geometric sequences
Random numbers What does it mean for a number to be random?
Presentation transcript:

Numerical Methods or Two Recipes for Pi CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009

A Fable The Maharaja of India was so pleased with one of his palace wise men, who had invented the game of chess, that he offered him a reward of his own choosing. The wise man told his Master that he would like just one grain of rice on the first square of the chess board, double that number of grains of rice on the second square, and so on: double the number of grains of rice on each of the next 62 squares on the chess board. This seemed to the ruler to be a modest request, so he called for his servants to bring the rice. 2

Rice def rice(): print "Square", "Grains" amount = 1 for s in range(1,64): print s, amount amount = amount * is starting value

Minute Rice How can we compute the amount of rice on the last square in one line? 2 ** 63 4

Compound Interest def compound_interest(principle, \ yearly_rate, months): print "Month", "Principle" monthly_rate = yearly_rate / 12.0 for m in range(months): print m, principle principle = principle + \ monthly_rate * principle 5

Compound Interest with Fixed Payment def compound_interest(principle, \ yearly_rate, months, monthly_payment): print "Month", "Principle" monthly_rate = yearly_rate / 12.0 for m in range(months): print m, principle principle = principle + \ monthly_rate * principle – \ monthly_payment 6

Compound Interest Until Paid Off def compound_interest(principle, yearly_rate, \ monthly_payment): print "Month", "Principle" monthly_rate = yearly_rate / 12.0 m = 0 while principle >= 0: print m, principle principle = principle + monthly_rate * \ principle - monthly_payment m = m + 1 7

Two Recipes for Pi 8

Recipe the First: the Gregory- Leibniz Series 9 What ingredients do we need to make Pi?

Gergory-Leibniz Pi def make_pi(terms): print "Terms", "Estimate" p = 0 for d in range(1,terms,4): p = p + (4.0/d) - (4.0/(d+2)) print d, p 10 from 1 to terms-1 by 4

Recipe the Second: Dartboard Pi 11

Dartboard Pi Suppose circular dartboard fit exactly into a 1 foot square Suppose you throw darts that are equally likely to hit any spot in the square The proportion of darts that hit the circle is proportional to the area of the circle 12

Dartboard Pi The proportion of darts that hit the circle is proportional to the area of the circle 13

Dartboard Pi import math import random def make_pi(darts): hits = 1 for i in range(darts): dx = random.random() dy = random.random() if math.sqrt((0.5-dx)**2 + \ (0.5-dy)**2) < 0.5: hits = hits + 1 print "I think Pi is", (4.0*hits)/darts 14

Monte-Carlo Algorithms This is an example of what is called a Monte-Carlo Algorithm One that uses random samples to estimate some value These kinds of algorithms are used throughout Chemistry Biology Physics Economics Wherever you need to estimate some quantity that is hard to determine exactly! 15

Course Status Assignment 2: Turn in by 10:00am Saturday Pre-read: Zelle, Chapter 4 Workshop: Mystery Topic 16