Graphing Algorithm

quadratic-equationIn this challenge we will write several procedures to graph different mathematical equations on screen using Python Turtle.

We will focus on:

  • Linear equations: y = ax + b
  • Quadratic equations: y = ax2 + bx + c
  • Trigonometric functions: e.g. y = cos(x)

(x,y) coordinates using Python Turtle?


xy-coordinatesOn the Python trinket used below the turtle screen is 400 pixels wide by 400 pixels high.

Look at the canvas below to understand how (x,y) coordinates work:

Linear Equation

y = ax + b

A linear equation produces a straight line when graphed on screen.

Your task:
Change the parameters used when calling the drawLine() procedure to graph the following equations:

  • y = 2x + 60
  • y = -x + 10
  • y = x
  • y = 1/2x

Quadratic Equation

y = ax2 + bx + c

Add another procedure called drawQuadraticEquation() that will take three parameters: a, b and c and be used to graph and display the matching quadratic equation.

Use this new procedure to graph the following equations:

  • y = x2 + 2x + 60
  • y = 1/2x2 – 3x + 20
  • y = x2
  • y = -x2 + 100

Trigonometric Functions

You can now add further procedures to draw the main trigonometric functions. To do so you will need to import the math library using an import statement.

import math

Here are the three main functions you will need to implement:

  • cosine: y = cos(x)
  • sine: y = sin(x)
  • tangent: y = tan(x)

Did you like this challenge?

Click on a star to rate it!

Average rating 4.5 / 5. Vote count: 2

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: , , ,