Sustainability Science 5060, Spring 2026 Homework #1 Due February 27, 2026 11:59 PM 1 Sustainability Science 5060, Fall 2021 Problem Set #1 Due October 15, 2021 11:59 PM Calculating the value of iteratively Imagine a series of regular polygons inscribed within a circle of unit radius. The figure at right shows a square (four sides, blue), an octagon (eight sides, red) and a hexadecagon (sixteen sides, green) inscribed in a circle (black). The perimeter of each of these polygons is an approximation to the circumference of the circle. Think of these polygons as successive iterations on the estimate of the circles circumference. The perimeter !! of the polygon at the kth iteration is !! = #!$!, where #! is the number of sides of the polygon and $! is the length of one of its sides. Since the circumference of the circle can be approximated by !!, and the circumference of a unit-radius circle is 2&, the estimate of & from the kth iteration is &! = #!$!/2. If each successive polygon has twice as many sides, then we have the following relations: #!”# = 2#! $!”# = (2)1 ,1 – $! 2 . $ / 1) Write a Python function side_k1 into which the the value $! is passed and which returns the value $!”#. 2) Write Python code that calls function side_k1 to estimate & using the two methods described below. For each method, write the result of each iteration, one line of output per iteration k. For each value of k, the code should print: (i) the value of k; (ii) the value of &! to ten decimal places; and (iii) the absolute value of difference between &! and & to two decimal places (including for the first and final iterations) in scientific notation. The output should have neat columns with decimal points aligned, and with header (i.e., label) rows at the beginning. a) Starting with ## = 4 (a square) for 2 = 1, write the Python code to estimate & using a while loop. (You will have to figure out what the value of $# is.) The code should loop until the absolute value of the difference between your estimate &! and the true value of & is less than 10%&. b) Same as (a), except use a for loop to iterate starting at 2 = 1 up to and including 2 = 20. Here is the first two lines of output both for parts 2a and 2b, not including column headers: 1 2.8284271247 3.13e-01 2 3.0614674589 8.01e-02 Grading This submission is worth 20% of your total course grade. The submission will be graded according to the following rubric, graded on a 100-point scale: 1) Code follows instructions and produces correct results (50 points): a) (Excellent: 50 to >30 pts): Code is responsive to instructions. Code runs and produces correct results with no or few changes. All assignment instructions are followed. b) (Good: 30 to >10 pts): Code deviates from instructions in minor ways. Code contains minor bugs on a few lines that the instructor can easily correct. Code follows nearly all assignment instructions. c) (Poor: 10 to >0 pts): Submission is not responsive to instructions or contains significant deviations. Code contains major coding errors or deviates significantly from assignment instructions. 2) Proper Python coding style (20 points): a) (Excellent: 20 to >12 pts): Variables have good mnemonic descriptors. Appropriate use is made of Python language features. Code is concise. Variable numerical types are appropriate. b) (Good: 12 to >4 pts): Variable names could be improved. Some duplicative or unnecessary code. Code does not make use of Python features to improve concision. c) (Poor: 4 to >0 pts): Poor variable names. Highly duplicative and significant blocks of unnecessary code. 3) Code documentation (20 points): a) (Excellent: 20 to >12 pts): Code is properly documented, with one informative comment every 12 lines of code. Comments describe authorship (including AI, if applicable) and purpose of code. b) (Good: 12 to >4 pts): Code is documented but could be better. c) (Poor: 4 to >0 pts): Code is poorly documented. 4) Code output (10 points): a) (Excellent: 10 to >6 pts): Code produces easy-to read, columnated, decimal-aligned table of output with headers. b) (Poor: 6 to >0 pts): Output is difficult to read or does not conform to assignment instructions. Submission Please submit your code through Courseworks as a single file of type .py (Python program file) or .ipynb (Python notebook). The filename should include your last name.

Leave a Reply
You must be logged in to post a comment.