Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Mathematics for Computer Science

Overview Notes

Prepared by
Dalos D. Miguel
Faculty
School of Accountancy, Management, Computing and Information Studies
Saint Louis University
Baguio City

II. The Equation of a Line:


1. The slope of a line

Two points in a plane determine a line. In essence, when two points are plotted in the
rectangular coordinate system, a line that passes through the two points may be drawn.

Given two points in a line, the slope of the line can be computed. The slope of a line is a
number that describes the steepness and the direction of the line. Given two points in a line, the
slope is the ratio of the difference of the ordinates and the difference of the abscissas of the two
points. If the first point is (x1,y1) and the second point is (x2,y2), then the slope is (y2-y1)/(x2-x1).
The slope of a line is usually denoted by m.
m = (y2-y1)/(x2-x1)

If the slope m is zero, the line is a horizontal line.


Consider for example a line that passes through (-2,3) and (4,3). The slope m is equal to (3-
3)/(4-(-2))=0/6=0

If the slope is a positive number, the line is inclined towards the right.
Consider for example a line that passes through ( -1,2) and (5,6). The slope m is equal to (6-
2)/(5-(-1))= 4/6 = 2/3. Now, try to show the line in the xy plane. Realize that the line is inclined
towards the right.

If the slope is a negative number, the line is inclined towards the left.
Consider for example a line that passes through (1,8) and (4,2). The slope m is equal to (2-
8)/(4-1)= -6/3=-2. Now, try to show the line in the xy plane. Realize that the line is inclined
towards the left.

Exercises:
Describe the slope of a horizontal line.
Describe the slope of a vertical line.

2. The Slope Intercept Form of the equation of a line.

The equation of line can be derived by substituting the slope of the line and the ordinate
of the point at which the line crosses the vertical axis in the general form of the equation of a line
that is called the slope intercept form.

1 | Page
The general form of the slope intercept form of the equation of a line is y = m*x + b. In
the general form of the equation, m is the slope and b is is the y intercept (the ordinate of the
point through which the line crosses the vertical or y axis).

For example, suppose we want the equation of the line that passes through (-1,2) and
(5,6). As determined previously, the slope of the line is (6-2)/(5-(-1)). The slope m=2/3. The y
intercept b can be determined by using the equation y=mx+b ( the slope-intercept form).
Because x and y in the equation correspond to the abscissa and ordinate, respectively, of any
point in the line, we may use one of the given points on the line such that the abscissa of the
point is x and the ordinate of the point is y.

Suppose we use (-1,2). x=-1, y=2 and m=2/3. Substituting x=-1, y=2 and m=2/3 in
y=mx+b; 2=(2/3)(-1)+b; b=2+2/3; b=8/3. The equation of the line is therefore y=(2/3)x+8/3.
Note that the equation may be written as 3y=2x+8. Similarly, the equation can be written as 2x-
3y+8=0. It may even be written as 2x-3y=-8.

It can be verified that the same equation is derived if the other point, that is (5,6) is used.
In this case, x=5, y=6 and m=2/3. By substituting x, y and m in y=mx+b; 6=(2/3)(5)+b; b=6-
10/3; b=8/3.

Exercise IIA (Filename: <YourName>Exercise2A.pdf)


1. Use the slope-intercept form to derive the equation of the line that passes through (1,8) and
(4,2).

2. Use the slope intercept form to derive the equation of the line that passes through (-2,3) and
(4,3). Describe the equation of a horizontal line.

3. Describe the equation of a vertical line.

4. What is the point-slope form of a line? Illustrate how an equation of a line is derived by using
the point-slope form.

5. Show an example of a simple program in Python that has something to do with deriving the
equation of a line.

The Regression line.


The slope intercept form of the equation of the line, together with principles of in Calculus, are
used in the derivation of a Regression Line. A Regression Line is the best fit line to a given set of
points. In a typical case, several paired values for two variables, an independent(x) and a
dependent variable(y), are generated from actual observation. Considering the pairs of values as
coordinates of points in the rectangular plane, a line is drawn such that the sum of the distances
of the points from the line is smallest.

2 | Page
Given: {(X1,Y1), (X2,Y2), …, (Xn,Yn)}
The values for a and b for y=ax+b may be known from the following system of two equations in
two unknowns.
Equation 1:
𝑛 𝑛 𝑛

∑ xi ∗ yi = 𝑎 ∗ ∑ 𝑥𝑖 2 + 𝑏 ∗ ∑ 𝑥𝑖 1
𝑖=𝑖 𝑖=1 𝑖=1
Equation 2:
𝑛 𝑛

∑ yi = 𝑎 ∗ ∑ 𝑥𝑖 1 + 𝑏 ∗ 𝑛
𝑖=1 𝑖=1
Where:
n = number of points = number of points
𝑛

∑ xi ∗ yi = (𝑥1) ∗ (𝑦1) + (𝑥2) ∗ (𝑦2) + ⋯ + (𝑥𝑛) ∗ (𝑦𝑛)


𝑖=𝑖

∑ 𝑥𝑖 2 = (𝑥1) ∗ (𝑥1) + (𝑥2) ∗ (𝑥2) + ⋯ + (𝑥𝑛) ∗ (𝑥𝑛)


𝑖=1

∑ 𝑥𝑖 1 = 𝑥1 + 𝑥2 + … + 𝑥𝑛
𝑖=1

∑ yi = 𝑦1 + 𝑦2 + … + 𝑦𝑛
𝑖=1

3 | Page
Exercise IIB. (Filename: <YourName>Exercise2B.pdf)
Based on the concept of the Regression line, derive the equation of a line that fits the given set of
points for the following case. Use your creativity in presenting your solutions. You may do it
manually, you may use a spreadsheet software, or you may use programming (Python).

1. For a particular stretch of a highway it is believed that there is a correlation between the
vehicle density(number of vehicles per 100 m) on the highway and the number of accidents
that occur. From causal observation, the number of accidents has been found to increase
with an increase in vehicle density up to a certain point. However, once the vehicle density
exceeds a certain value, the average vehicle speed is reduced due to congestion, thereby
reducing the number of accidents. To predict accident rates and as an aid to produce an
improved highway design, we wish to develop equations relating the vehicle density to the
number of accidents from observed data.

Vehicle Density (x) Number of Accidents (y)

1.4 3

2.0 6

2.3 4

4.5 7

6.2 10

6.7 15

7.0 11

8.5 18

9.0 13

12.7 17

13.1 15

17.7 16

18.5 11

20.3 5

4 | Page
(Recommended additional exercise)

Derive a regression line that relates the year and the population as shown in the following
table. Let y be population and x be year (i.e. Population depends on year).

Year population(million)

1950 20.2

1955 22.9

1960 25.29

1965 30.55

1970 34.7

1975 40.3

1980 47.1

1985 52.3

1990 59.2

1995 68.2

2000 78.78

2005 85.5

2010 91.35

5 | Page
Additional Concepts That Must be Reviewed

Distance between Two Points ( 2-dimensional plane)


The distance between two points with given coordinates can be determined by a formula. The
general formula (i.e. the distance formula) for getting the distance, d, between two points is
d2 = (x2-x1)2 + (y2-y1)2 where (x1,y1) is the first point and (x2,y2) is the second point.

Illustration
Determine the distance between (-1,2) and (5,6).

Solution:
Substitute the coordinates of the given points in the distance formula.

(d)2 = (5-(-1))2 + (6-2)2.

d2 = 36 + 16

d2 = 52

Get the square of both sides. The distance is the positive root of the right side.

d = square root of 52 = square root of (4)(13) = 2(square root of 13).

Distance between Two Points ( 3-dimensional plane)


The distance formula can be extended to cover the triple coordinates in the case where the
points are in a 3-dimensional plane. In a 3 dimensional place, one point may be identified as
(x1,y1,z1) and another point may be identified as (x2,y2,z2).

d2 = (x2-x1)2 + (y2-y1)2 + (z2-z1)2 where (x1,y1,z1) is the first point and (x2,y2,z3) is the second
point.

Distance between Two Points ( n-dimensional plane)


d2 = (y1-x1)2 + (y2-x2)2 + (y3-x3)2 + … + (yn-xn)2 (where (x1,x2, x3, …,xn is the first point and
(y1,y2,y3,…,yn is the second point.

6 | Page
References:

Banks, J., et al. (1996). Discrete Event System Simulation. 2nd Edition. Prentice Hall, Inc. New Jersey. U.S.A.
Gosset, E. (2003). Discrete Mathematics with Proof. Pearson Education Inc. USA.

Hillier, F. and M. Hillier. (2011). Introduction to Management Science A Modeling and Case Studies Approach with
Spreadsheets. 4th Edition. McGraw-Hill Education. Singapore.

Janacek,G and M. Lemmon. (2011). Mathematics for Computer Science. Gareth J. Janacek, Mark Lemmon Close &
Ventus Publishing

Love, C. & E. Rainville. (1981). Differential and Integral Calculus. . Macmillan Publishing Co., Inc. USA.

Rainville, E. & P. Bedient. (1974). Elementary Differential equations. Macmillan Publishing Co., Inc. USA.

Rosen, K. (2001). Discrete Mathematics and Its Applications. Mc-Graw Hill Book Co. Singapore.

Walpole, R.(1997). Introduction to Statistics. 3rd Edition. Prentice Hall International, Inc. Singapore.

7 | Page

You might also like