# Slope

In mathematics, the slope or gradient of a line is a number that describes the direction of the line on a plane. Often denoted by the letter m, slope is calculated as the ratio of the vertical change to the horizontal change ("rise over run") between two distinct points on the line, giving the same number for any choice of points.
The line may be physical – as set by a road surveyor, pictorial as in a diagram of a road or roof, or abstract. An application of the mathematical concept is found in the grade or gradient in geography and civil engineering.
The steepness, incline, or grade of a line is the absolute value of its slope: greater absolute value indicates a steeper line. The line trend is defined as follows:
* An "increasing" or "ascending" line goes up from left to right and has positive slope: $m>0$.
* A "decreasing" or "descending" line goes down from left to right and has negative slope: $m<0$.
Special directions are:
* A "(square) diagonal" line has unit slope: $m=1$
* A "horizontal" line (the graph of a constant function) has zero slope: $m=0$.
* A "vertical" line has undefined or infinite slope (see below).
If two points of a road have altitudes y$_1$ and y$_2$, the rise is the difference (y$_2$ − y$_1$) = Δy. Neglecting the Earth's curvature, if the two points have horizontal distance x$_1$ and x$_2$ from a fixed point, the run is (x$_2$ − x$_1$) = Δx. The slope between the two points is the difference ratio:
    $m={\frac {\Delta y}{\Delta x}}={\frac {y_{2}-y_{1}}{x_{2}-x_{1}}}.$
Through trigonometry, the slope m of a line is related to its angle of inclination θ by the tangent function
    $m=\tan(\theta ).$
Thus, a 45° rising line has slope m = +1, and a 45° falling line has slope m = −1.
Generalizing this, differential calculus defines the slope of a plane curve at a point as the slope of its tangent line at that point. When the curve is approximated by a series of points, the slope of the curve may be approximated by the slope of the secant line between two nearby points. When the curve is given as the graph of an algebraic expression, calculus gives formulas for the slope at each point. Slope is thus one of the central ideas of calculus and its applications to design.

## Notation

There seems to be no clear answer as to why the letter m is used for slope, but it first appears in English in O'Brien (1844) who introduced the equation of a line as "y = mx + b", and it can also be found in Todhunter (1888) who wrote "y = mx + c".

## Definition

The slope of a line in the plane containing the x and y axes is generally represented by the letter m, and is defined as the change in the y coordinate divided by the corresponding change in the x coordinate, between two distinct points on the line. This is described by the following equation:
    $m={\frac {\Delta y}{\Delta x}}={\frac {{\text{vertical}}\,{\text{change}}}{{\text{horizontal}}\,{\text{change}}}}={\frac {\text{rise}}{\text{run}}}.$
(The Greek letter delta, Δ, is commonly used in mathematics to mean "difference" or "change".)
Given two points $(x_{1},y_{1})$ and $(x_{2},y_{2})$, the change in $x$ from one to the other is $x_{2}-x_{1}$ (run), while the change in $y$ is $y_{2}-y_{1}$ (rise). Substituting both quantities into the above equation generates the formula:
    $m={\frac {y_{2}-y_{1}}{x_{2}-x_{1}}}.$
The formula fails for a vertical line, parallel to the $y$ axis (see Division by zero), where the slope can be taken as infinite, so the slope of a vertical line is considered undefined.

### Examples

Suppose a line runs through two points: P = (1, 2) and Q = (13, 8). By dividing the difference in $y$-coordinates by the difference in $x$-coordinates, one can obtain the slope of the line:
    $m={\frac {\Delta y}{\Delta x}}={\frac {y_{2}-y_{1}}{x_{2}-x_{1}}}={\frac {8-2}{13-1}}={\frac {6}{12}}={\frac {1}{2}}.$
    Since the slope is positive, the direction of the line is increasing. Since |m| < 1, the incline is not very steep (incline < 45°).
As another example, consider a line which runs through the points (4, 15) and (3, 21). Then, the slope of the line is
    $m={\frac {21-15}{3-4}}={\frac {6}{-1}}=-6.$
    Since the slope is negative, the direction of the line is decreasing. Since |m| > 1, this decline is fairly steep (decline > 45°).

## Algebra and geometry

* If $y$ is a linear function of $x$, then the coefficient of $x$ is the slope of the line created by plotting the function. Therefore, if the equation of the line is given in the form then $m$ is the slope. This form of a line's equation is called the slope-intercept form, because $b$ can be interpreted as the y-intercept of the line, that is, the $y$-coordinate where the line intersects the $y$-axis.
    $y=mx+b$
* If the slope $m$ of a line and a point $(x_{1},y_{1})$ on the line are both known, then the equation of the line can be found using the point-slope formula:
    $y-y_{1}=m(x-x_{1}).$
* The slope of the line defined by the linear equation is
    $ax+by+c=0$
    $-{\frac {a}{b}}$.
* Two lines are parallel if and only if they are not the same line (coincident) and either their slopes are equal or they both are vertical and therefore both have undefined slopes.
* Two lines are perpendicular if the product of their slopes is −1 or one has a slope of 0 (a horizontal line) and the other has an undefined slope (a vertical line).
* The angle θ between −90° and 90° that a line makes with the x-axis is related to the slope m as follows: and
    $m=\tan(\theta )$
    $\theta =\arctan(m)$ (this is the inverse function of tangent; see inverse trigonometric functions).

### Examples

For example, consider a line running through points (2,8) and (3,20). This line has a slope, m, of
    ${\frac {(20-8)}{(3-2)}}=12.$
One can then write the line's equation, in point-slope form:
    $y-8=12(x-2)=12x-24.$
or:
    $y=12x-16.$
The angle θ between −90° and 9000° that this line makes with the x-axis is
    $\theta =\arctan(12)\approx 85.2^{\circ }.$
Consider the two lines: y = −3x + 1 and y = −3x − 2. Both lines have slope m = −3. They are not the same line. So they are parallel lines.
Consider the two lines y = −3x + 1 and y = ⁠x/3⁠ − 2. The slope of the first line is m$_1$ = −3. The slope of the second line is m$_2$ = ⁠1/3⁠. The product of these two slopes is −1. So these two lines are perpendicular.

## Statistics

In statistics, the gradient of the least-squares regression best-fitting line for a given sample of data may be written as:
    $m={\frac {rs_{y}}{s_{x}}}$,
This quantity m is called as the regression slope for the line $y=mx+c$. The quantity $r$ is Pearson's correlation coefficient, $s_{y}$ is the standard deviation of the y-values and $s_{x}$ is the standard deviation of the x-values. This may also be written as a ratio of covariances:
    $m={\frac {\operatorname {cov} (Y,X)}{\operatorname {cov} (X,X)}}$

## Calculus

The concept of a slope is central to differential calculus. For non-linear functions, the rate of change varies along the curve. The derivative of the function at a point is the slope of the line tangent to the curve at the point and is thus equal to the rate of change of the function at that point.
If we let Δx and Δy be the distances (along the x and y axes, respectively) between two points on a curve, then the slope given by the above definition,
    $m={\frac {\Delta y}{\Delta x}}$,
is the slope of a secant line to the curve. For a line, the secant between any two points is the line itself, but this is not the case for any other type of curve.
For example, the slope of the secant intersecting y = x$^2$ at (0,0) and (3,9) is 3. (The slope of the tangent at x = 3⁄2 is also 3 − a consequence of the mean value theorem.)
By moving the two points closer together so that Δy and Δx decrease, the secant line more closely approximates a tangent line to the curve, and as such the slope of the secant approaches that of the tangent. Using differential calculus, we can determine the limit, or the value that Δy/Δx approaches as Δy and Δx get closer to zero; it follows that this limit is the exact slope of the tangent. If y is dependent on x, then it is sufficient to take the limit where only Δx approaches zero. Therefore, the slope of the tangent is the limit of Δy/Δx as Δx approaches zero, or dy/dx. We call this limit the derivative.
    ${\frac {\mathrm {d} y}{\mathrm {d} x}}=\lim _{\Delta x\to 0}{\frac {\Delta y}{\Delta x}}$
The value of the derivative at a specific point on the function provides us with the slope of the tangent at that precise location. For example, let y = x$^2$. A point on this function is (−2,4). The derivative of this function is dy⁄dx = 2x. So the slope of the line tangent to y at (−2,4) is 2 ⋅ (−2) = −4. The equation of this tangent line is: y − 4 = (−4)(x − (−2)) or y = −4x − 4.

## Difference of slopes

An extension of the idea of angle follows from the difference of slopes. Consider the shear mapping
    $(u,v)=(x,y){\begin{pmatrix}1&v\\0&1\end{pmatrix}}.$
Then $(1,0)$ is mapped to $(1,v)$. The slope of $(1,0)$ is zero and the slope of $(1,v)$ is $v$. The shear mapping added a slope of $v$. For two points on $\{(1,y):y\in \mathbb {R} \}$ with slopes $m$ and $n$, the image
    $(1,y){\begin{pmatrix}1&v\\0&1\end{pmatrix}}=(1,y+v)$
has slope increased by $v$, but the difference $n-m$ of slopes is the same before and after the shear. This invariance of slope differences makes slope an angular invariant measure, on a par with circular angle (invariant under rotation) and hyperbolic angle, with invariance group of squeeze mappings.

## Slope (pitch) of a roof

The slope of a roof, traditionally and commonly called the roof pitch, in carpentry and architecture in the US is commonly described in terms of integer fractions of one foot (geometric tangent, rise over run), a legacy of British imperial measure. Other units are in use in other locales, with similar conventions. For details, see roof pitch.

## Slope of a road or railway

There are two common ways to describe the steepness of a road or railroad. One is by the angle between 0° and 90° (in degrees), and the other is by the slope in a percentage. See also steep grade railway and rack railway.
The formulae for converting a slope given as a percentage into an angle in degrees and vice versa are:
    ${\text{angle}}=\arctan \left({\frac {\text{slope}}{100\%}}\right)$ (this is the inverse function of tangent; see trigonometry)
and
    ${\mbox{slope}}=100\%\times \tan({\mbox{angle}}),$
where angle is in degrees and the trigonometric functions operate in degrees. For example, a slope of 100% or 1000‰ is an angle of 45°.
A third way is to give one unit of rise in say 10, 20, 50 or 100 horizontal units, e.g. 1:10. 1:20, 1:50 or 1:100 (or "1 in 10", "1 in 20", etc.) 1:10 is steeper than 1:20. For example, steepness of 20% means 1:5 or an incline with angle 11.3°.
Roads and railways have both longitudinal slopes and cross slopes.
* Slope warning sign in the Netherlands
* Slope warning sign in Poland
* A 1371-meter distance of a railroad with a 20‰ slope. Czech Republic
* Steam-age railway gradient post indicating a slope in both directions at Meols railway station, United Kingdom

## Other uses

The concept of a slope or gradient is also used as a basis for developing other applications in mathematics:
* Gradient descent, a first-order iterative optimization algorithm for finding the minimum of a function
* Gradient theorem, theorem that a line integral through a gradient field can be evaluated by evaluating the original scalar field at the endpoints of the curve
* Gradient method, an algorithm to solve problems with search directions defined by the gradient of the function at the current point
* Conjugate gradient method, an algorithm for the numerical solution of particular systems of linear equations
* Nonlinear conjugate gradient method, generalizes the conjugate gradient method to nonlinear optimization
* Stochastic gradient descent, iterative method for optimizing a differentiable objective function