I have discussed functions before but I assumed nice continuous functions in the discussion. This is OK since most functions encountered in mathematics are of this type. But there are not so well-behaved functions called piecewise functions. These are also called hybrid functions in some textbooks, but I think piecewise is a bit more descriptive.
These kinds of functions are used in many areas of mathematics, engineering, science, and finance: pricing strategies, taxation, electric field modelling, imaging, computer science, digital art, aircraft design. This is why it is covered in high school maths.
So what is a piecewise function? As the name implies, it is a function that is defined differently over different intervals (pieces) of its independent variable (usually x). Here is an example:

So this function is −1 if the x used to evaluate this function is less than 0 (all negative numbers), it is the square root of x, if x is greater than or equal to 0 but strictly less that 2, and it is 3 if x is greater than or equal to 2. The plot of this function looks like

You can clearly see that the form of the function changes depending on where you are on the x-axis. Here’s another example

The graph of this function is

When working with this function, you would have to split the problem into parts. For example, given this function, solve f(x) = 5. You can use the graph to see that the solution will be in the third part of the function. But if you didn’t have this graph to guide you, how would you solve that algebraically?
You would set each part of the function equal to 5 and solve. If the answer is in the part of the x-axis where that function part is defined, then that is a solution. If not, then it is not a solution. For this example, first solve x3 = 5. The answer is x ≈ 1.71 (≈ means “approximately). Since 1.71 is not less than 0 where the x3 part is defined, this is not an answer.
Now solve x2 = 5, The answer is x ≈ ± 2.24. There are two answers here but neither is greater than 0 and less than 2. Finally try x/2 + 3 = 5. The answer is x = 4 which is greater than 2 so that is our answer.
In calculus, there are definitions for continuity and differentiability (smoothness) of a function. For those not familiar with calculus, you would probably say that the above graph is continuous as you could draw it without lifting your pencil off the paper. And you would be correct. But is the above graph smooth where the different parts of the function join? It turns out, using a process called limits, the curve is smooth at the origin, but not at the point (2, 4). This probably makes sense to you as there is a corner at that point and there would be a sharp change in direction a pencil would take at that point. I will talk about what limits are in my next post.