How to represent a graph in a function?

For example, I used 3 functions :

$$f(x)=x^2$$ $$g(x)=x$$ $$h(x)=3$$

These 3 functions were plotted on the same graph and the result (after edit) is as given below

How would you represent the below graph in a function, lets say $k(x)$ ?

enter image description here


You can simple define $k$ to be a piecewise function:

$$k(x) := \begin{cases}x^2 & 0 \le x < 1\\ x & 1 \le x < 3\\3 & 3 \le x\end{cases}$$

Now if you really don't like that, you can work out something using $\min$:

$$k(x) = \min(x^2, x, 3)$$

But not all piecewise functions have such a nice "closed" form.

| cite | improve this answer | |

You'd use a piecewise function. In this case, we have $$ k(x) = \begin{cases} x^2 & 0 \leq x \lt 1 \\ x & 1 \leq x \lt 3 \\ 3 & x \geq 3 \end{cases} $$

| cite | improve this answer | |
  • $\begingroup$ This is incorrect. What makes you think $k(x)$ is defined for $-18$ when it is not on the graph? $\endgroup$ – MathematicsStudent1122 Feb 19 '16 at 18:46
  • 4
    $\begingroup$ @MathematicsStudent1122 That seems more like a fault in the question than a fault in the answer; it's ambiguous and it seems rather unfair to call this incorrect when it does coincide with what we see in the range we see it in (and we were not given any instruction about the range we don't see it in) $\endgroup$ – Milo Brandt Feb 19 '16 at 21:33
  • $\begingroup$ @MiloBrandt When Student originally commented, I had $-\infty \lt x \lt 1$ for the first case; it could still work due to the ambiguity you mentioned, but it was potentially inaccurate. $\endgroup$ – DylanSp Feb 19 '16 at 21:37
  • $\begingroup$ @DylanSp After the edit, I have removed the downvote. $\endgroup$ – MathematicsStudent1122 Feb 19 '16 at 22:03

Depending on the context, it might also be useful to represent the function using Heaviside's step function $H(x)$, which equals $0$ for $x < 0$ and $1$ for $x > 0$. You could also define $H(0)=0$ or $H(0) = 1$ if you want, but it might not be so important, again depending on the context.

With this notation, your function may be written as $$k(x) = x^2(H(x)-H(x-1))+x(H(x-1)-H(x-3))+3H(x-3),$$ or, collecting the Heaviside terms, $$k(x) = x^2H(x)+x(1-x)H(x-1)+(3-x)H(x-3).$$

This is really just a shorthand notation for the piecewise function we're dealing with, but it is very useful for example if you're working with distributions. Also note that it doesn't really matter whether we define $H(0)=0$ or $H(0) = 1$, as $k$ evaluates to the same value at $x=1$ and $x=3$ either way, as clearly seen from the second expression of $k$.

| cite | improve this answer | |
  • 1
    $\begingroup$ In this case defining H(0)=0 or H(0)=1 is not important, but with a discontinuous piecewise function it could matter. $\endgroup$ – Nick Feb 20 '16 at 17:40
  • $\begingroup$ @Nick Yes, indeed. $\endgroup$ – Étienne Bézout Feb 20 '16 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.