# How to generate a function from a given graph?

Please provide any formula or step-by-step guide on how to generate a function for the following graph.

Graph logic:

Part 1 $$\longrightarrow$$ where $$x \leq 3$$ $$\longrightarrow$$ linear relation.

Part 2 $$\longrightarrow$$ when $$3 \leq x \leq 6$$ $$\longrightarrow$$ $$y$$ remains unchanged.

Then, again part 1 with $$3 < x < 9$$ $$\longrightarrow$$ linear relation.

Then part 2 when $$y$$ remains unchanged.

Thanks!

EDIT: Values for $$x$$ and $$y$$

x y
0 0
1 1
2 2
3 3
4 3
5 3
6 3
7 3
8 3
9 3
10 4
11 5
12 6
13 6
14 6
15 6
16 6
17 6

and so on.

I am trying to create an interpolator for the following case:

Interpolation time 3500 ms
Value start = 0, end = 1


Firstly, the 500 ms value increases by the formula (end/3500)*interpolated time.

Then 1000 ms value remains unchanged.

Then 500 ms again value increases.

Then 1000 ms value remains unchanged.

Then 500 ms again value increases.

• What is the value of $f(x) = y$ in the interval $[3, 9]$? You have to construct a piecewise function. Define $f(x)$ on separate intervals of $x$, just like you have verbally done in your question. Commented Apr 23, 2019 at 15:47
• Do you know how to get the equation of of line if you are given two points on the line? When you ask a question here it helps a lot if you tell us what you have tried and what you know about the question. Otherwise, we don't know where to start with an answer. Commented Apr 23, 2019 at 15:48
• @Joshiepillow Thanks, thats was my mistake Commented Apr 23, 2019 at 16:01
• @saulspatz I've updated my question with a bit more explanations. Please check it Commented Apr 23, 2019 at 16:02
• @JacobCheverie I've updated my question with a bit more explanations. Please check it Commented Apr 23, 2019 at 16:03

$$y = x - 2a/3$$ for $$a \leq x < a + 3$$

$$y = a/3 +3$$ for $$a+3 \leq x < a + 9$$

Where $$a$$ is defined as all numbers for which $$a \bmod 9 = 0$$.

Basically, $$a$$ is divisible by 9.

Tried this on Desmos. It works but you’ll have to manually type in every value of $$a$$.

If you don’t want to use discrete functions, you can use sigmoid approximation.

$$f_1(x) = \lim_{k\rightarrow \infty}\frac{1}{1 + e^{-k(x)}} \cdot \frac{1}{1 + e^{k(x-3)}}$$

The above function will return approximately $$0$$ if $$x$$ is not in the interval $$(0,3)$$, otherwise $$1$$. Likewise you can create your own functions for other intervals.

\begin{align} f_2(x) &= \lim_{k\rightarrow \infty}\frac{1}{1 + e^{-k(x-3)}} \cdot \frac{1}{1 + e^{k(x-9)}} \\ f_3(x) &= \lim_{k\rightarrow \infty}\frac{1}{1 + e^{-k(x-9)}} \cdot \frac{1}{1 + e^{k(x-12)}} \\ f_4(x) &= \lim_{k\rightarrow \infty}\frac{1}{1 + e^{-k(x-12)}} \cdot \frac{1}{1 + e^{k(x-17)}} \end{align}

Now, multiply all the functions with their lines.

$$f(x) = f_1 \cdot x + f_2 \cdot 3 + f_3 \cdot (x-6) + f_4 \cdot 6$$

Here is an example MATLAB code and the result graph.