In 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-coordinates](/wp/wp-content/uploads/xy-coordinates.png)
Look at the canvas below to understand how (x,y) coordinates work:
Linear Equation
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
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)