# Gradient Calculator

Welcome to the **gradient calculator**, where you'll have the opportunity to learn how to calculate the gradient of a line going through two points. "*What is the gradient?*" you may ask. Well, have you ever looked at a mountain and said to yourself, "*Wow, that mountain is quite steep, but not as steep as the one next to it!*"? And if that kind of question has left you wondering how their steepness compares, **you've come to the right place**! Keep reading to know the gradient definition.

If you want to find the gradient of a non-linear function, we recommend checking the average rate of change calculator.

## What is the gradient?

Before we look at what the gradient is, **let's return to our mountain scene** and the absolutely crucial question of steepness.

Let's say you're skiing down a slope when **The Big Question** hits you. You stop and think about it before going any further. As we've mentioned above, **all you need is two points to find the gradient**, so why not be a little self-centered and **choose yourself as the... well, center**, that is, the point `(x₁,y₁) = (0,0)`

on the plane.

Now we're left with **finding a second point**, `(x₂,y₂)`

, up or down the slope. You look around to find some particularly bushy tree or a pretty young skier. Or an old smelly one for that matter; I'm not judging.

Tell the tree or the skier to stand still while you use your handy ruler (that you always carry around with you, of course) to count **how much higher/lower they are from you** (that will be `y₂`

) and **how far they are from you** (that will be `x₂`

). **Remember to count the distance between you two horizontally, not parallel to the slope**. And there you have it! The ratio of `y₂ / x₂`

is your gradient or the steepness of the mountain at that point.

For sticking around while you perform your quick experiment, go and buy that skier some hot chocolate or hug the tree. They deserve as much.

## Gradient definition

An informal definition of the **gradient** is as follows: it is a mathematical way of measuring **how fast a line rises or falls**. Think of it as a number you assign to a hill, a road, a path, etc. that tells you how much effort you have to put into cycling it (related to the calories burned by biking). **If you're going uphill**, you must struggle to reach the peak, so the energy needed (i.e., the gradient) is large. **If you're going downhill**, you don't even have to pedal to pick up speed, so the effort is, in fact, negative. And **if you're on flat ground**, it neither helps nor makes it harder, so it is neutral or has a gradient of zero.

And what **if you're facing a vertical slope**? Well, it's not always clear if you want to fall down it (which is effortless) or go scrambling up it. Therefore, in this case, the **gradient is undefined**.

## How to calculate gradient?

We calculate the gradient the same way we calculate the slope. **We find two points** and denote them with the cartesian coordinates `(x₁,y₁)`

and `(x₂,y₂)`

, respectively. This is also the notation used in the calculator. Note that we used the same symbols in the real-life example. We want to see how they relate to each other, that is, what is the rise over run ratio between them. It is described by the **gradient formula**:

`gradient = rise / run`

with `rise = y₂ - y₁`

and `run = x₂ - x₁`

. **The rise** is how much higher/lower the second point is from the first, and **the run** is how far (horizontally) they are from each other. We talk more about it in the dedicated rise over run calculator.

## Gradient formula: example of application

Now that we know the gradient definition, it's time to **see the gradient calculator in action** and go through how to use it together, step by step:

- Find two arbitrary points on the line you want to study and find their cartesian coordinates. Let's say we want to calculate the gradient of a line going through points
`(-2,1)`

and`(3,11)`

. - Take the first point's coordinates and put them in the calculator as
`x₁`

and`y₁`

. - Do the same with the second point, this time as
`x₂`

and`y₂`

. - The calculator will automatically use the gradient formula and count it to be
`(11 - 1) / (3 - (-2)) = 2`

. - Enjoy the knowledge of how steep the slope of your line is, and go tell all your friends about it!

## Common misconceptions and mistakes

You may ask yourself, "*Hold on, I think I've seen this elsewhere. Doesn't something similar happen when you count the slope or the rise over run?*" You're absolutely right. **All three concepts: gradient, slope, and rise over run, describe the same thing**, so don't worry, as there is no difference between them.

You may also wonder how steep is *steep*; that is, what does the 2 in the above example tell us. Is it a lot, or is it not? Is the pretty skier going to be impressed by this number? Well, **it's all a matter of perspective**, and some may say one thing, while others will say the opposite. As a point of reference, you should remember that having a line parallel to the horizon is considered neutral here, as the gradient equals zero. When it rises (or falls), it becomes more and more like a line perpendicular to the horizon, where the slope goes to infinity when it rises (or minus infinity when it falls).