ELI5: Explain Like I'm 5

Piecewise linear function

Okay, so imagine you have a toy train that moves on a track. The train can only go straight, but the track is made up of different parts that slope up or down.

A piecewise linear function is kind of like that track. It’s a way to describe how something – like the height of the track – changes depending on where you are. But instead of a train moving along it, we’re talking about numbers that change based on the input.

Let’s say we have a piecewise linear function that looks like this:

f(x) = { 3x - 4 if x ≤ 2
{ 5x + 1 if x > 2

The function is split into two parts, depending on the input (the x value). If x is less than or equal to 2, we use the first part of the function: 3 times x, minus 4. If x is greater than 2, we use the second part of the function: 5 times x, plus 1.

So let’s plug in some numbers and see how this works.

If we put x = 1 into the function, we’re using the first part:

f(1) = 3(1) - 4 = -1

But if we put x = 3 into the function, we’re using the second part:

f(3) = 5(3) + 1 = 16

So the function changes how it works depending on the input value. Kind of like how the train track changes slopes depending on where you are.
Related topics others have asked about: