Notes and Code | Outcome |
---|---|
General Equation for a Straight Line
We want a program that can handle any straight line equation we throw at it, so we need to work with the general equation:
$$ y = mx + b \tag{1}$$
We can use it to find and do things like:
|
Example: Graph of the linear function: $$ y = 2x + 1 $$ where, $$ m = 2 , \,\,\, b = 1 $$ |
Creating a Class
Notice that:
|
If you run this code, nothing will happen. Just like with a function, classes are stored in memory until they are used.
|
Using the
Let's use the |
Show Notes ▼
|
ExerciseFind which line has an x-intercept closer to zero of the two lines: $$ y = 4x - 5 \tag{4}$$ $$ y = x + 2 \tag{5}$$ |
Code:
Show Notes ▼
Show Notes ▼
|
Methods: Finding the y values given xSomething we'll very likely want to do if we have an equation is to find the value of y for a given x. To do so we'll create a method within the class. A method is a function that exists inside a class.
|
Code.
|
Exercise: find x given y
Add a method to the class that calculates the x value for a given y. Use this method to find x value when:
$$ y = 11 $$
for the line
$$ y = 2x + 1 $$
|
Code.
Show Notes ▼
Show Notes ▼
|
Exercise: perpendicular slope
Add a method to: calculate the slope of a line perpendicular to the given line.
|
Code.
Show Notes ▼
Show Notes ▼
|
Exercise: Check if a point is on the line
Add a method to: determine if a given point (x,y) is on the line.
Your method should return 'True' if the point is on the line and 'False' if not. |
Code.
Show Notes ▼
Results.
Show Notes ▼
|