Homework 6: Plotting Functions

Assigned
Wednesday September 21, 2016
Due
noon, Friday September 23, 2016
Summary
The goal of this assignment is to get more experience with functions, loops, and using turtles.
Collaboration
Do this assignment with your assigned partner.
Submitting
Submit a Python program using the online turnin form. See below.
Scoring
12 points

Assignment

Create a file named turtleplot.py in which you will write your code. Write the following functions:

Part 1. Sums of series

Write the following functions:

Part 2. Plotting with a turtle

Write a function tplot(tortoise, f) that takes as parameters a turtle and a function, and uses the turtle to plot the function.

Here's an algorithm outline:

Part 3. Writing a main function

Write a main function with the following code. Remember to import the turtle module at the top of your file.

def main():
turtle.setworldcoordinates(0, -20, 40, 80)
plotter = turtle.Turtle()
plotter.speed(0)
plotter.penup()
tplot(plotter, square)
screen = plotter.getscreen()
screen.exitonclick()

If your tplot function is working, you should see Plotter the turtle plotting the points of the square function:

turtle plot of the square function

Try plotting the other functions as well by changing the argument to tplot from square to another function.

You can also pass in built-in functions from math, for example passing math.sin looks like this: turtle plot of the sin function

Part 4. Comparing functions

Modify the main function so that it plots several functions in different colors as follows:

black
identity
red
square
orange
math.log2
blue
sum_to_n
indigo
sum_odds
purple
sum_frac

When you plot these functions together, do you notice any interesting relationships between them? Write a comment in your code.

Above & beyond

Some ideas:

Submitting your work

Submit one file, turtleplot.py, using the turnin form.

Point distribution


Janet Davis (davisj@whitman.edu).
This assignment was developed with Andy Exley based on exercises in the textbook.

Created September 19, 2016
Last revisedSeptember 22, 2016, 01:59:11 PM PDT
CC-BY-NC-SA This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.