Constructing an increasing function with prescribed values at three points

231 Views Asked by At

This should probably be very simple, but I'm just not very skilled in math :S. I want a function that takes one variable, x, ranging from 0-1. As the input approaches 0 so should the output. As the input approaches 1, the output should approach any roof I would like. For instance 5. It should be true that increasing the input will always increase the output. It should be true that input 0.5 outputs 1.

so naturally input 0-0.5 should output 0-1, input 0,5-1 should output 1-roof

What would the body of such a function look like? Is it maybe not as simple as I think?

2

There are 2 best solutions below

3
On BEST ANSWER

There are an infinite number of functions that satisfy your criteria. By the statement of your problem, you care that the function be continuous at $x=0.5$, but not necessarily that it be differentiable. In that case, attack it as a piecewise problem.

Acknowledging that there are many ways to construct the function, we can simplify the analysis considerably by considering only combinations of powers of $x$. Another answer considered the restricted case of a 2nd order polynomial. That works because 2nd order polynomials can be entirely determined by 3 points. In this case, the three points are $(0,0)$, $(1/2, 1)$, and $(1,M)$ (where I have used the symbol $M$ to represent the "roof" value in the question).

I will also use the fact that any positive-definite power of $x$ is monotonically increasing, as is any positive multiple of it. So let's treat each interval separately.

Interval 1: $0\le x \le 1/2$

We would like a function that starts at $0$ at the beginning of the interval ($x=0$) and grows to $1$ by the time $x=0.5$. So let's try something of the following form:

$$f_{a}(x) = cx^{a},\space\space a>0,\space\space c>0.$$

I've put a subscript $a$ on $f$ to denote the power of $x$ I'm using. The actual value of $a$ can be any strictly positive real number. We must solve for $c$ given the constraints on the endpoints of the interval. Clearly, $f_{a}(0)=0$ for any value of $c$, so we're good there. The other constraint is

$$ f_{a}(1/2)=c\cdot({1/2})^{a}=1.$$

Solving this equation, we get $c=2^{a}$, so finally our function on the interval becomes

$$f_{a}(x)=2^{a}x^{a}=(2x)^{a},\space a>0.$$

If we want the function to be linear on the interval, we can pick $a=1$, and then we have $f_{1}(x)=2x$. We could drop the parameter subscript on $f$ at this point, since we've actually picked a single value. But note that we could also have a combination of multiple functions of this type that still satisfy the constraints. For example

$$F(x) = {f_{1}(x)\over 3} + {f_{2}(x)\over 3} + {f_{37.2}(x)\over 3}$$

is a perfectly valid function, since

$$F(0) = {f_{1}(0)\over 3} + {f_{2}(0)\over 3} + {f_{37.2}(0)\over 3} = 0+0+0=0$$

and

$$F(1/2) = {f_{1}(1/2)\over 3} + {f_{2}(1/2)\over 3} + {f_{37.2}(1/2)\over 3} = {1\over 3}+{1\over 3}+{1\over 3} = 1.$$

Interval 2: $1/2 < x \le 1$

For this interval, we know that we are starting with the function having the value $1$ at $x=1/2$. Otherwise, it's very similar to the first interval. So we start with $1$ and add something that has the value zero at $x=1/2$, like so

$$g_{b}(x) = 1 + c\cdot(x-1/2)^{b},\space\space b>0, \space c>0$$.

We do the same thing as above, looking this time at the values of $g_{b}(1/2)$ and $g_{b}(1)$. I've (cleverly) constructed the form of the function to satisfy the constraint at $x=1/2$ trivially, since the second term is just $0$ there. Setting the function equal to $M$ at $x=1$ gives $c=(M-1)\cdot2^{b}$, and the function may be written

$$g_{b}(x)=1 + 2^{b}(M-1)(x-1/2)^{b},\space b>0$$.

If you want just a linear function on this interval, set $b=1$ to get

$$g_{1}(x)=1+2(M-1)(x-1/2)= 2-M+2(M-1)x$$.

Again, you can make any combination of functions of this form such that the constraints are still satisfied.

Edit: Expanded answer and explained the notation a bit more.

1
On

You are right, it seems to be more complicated. The old "solution" is not increasing for every choice of $roof$. If you don't want a complicated solution I suggests

$f(x)=(2x(1-\lfloor 2x\rfloor)+(2(roof-1)x+2-roof)\lfloor 2x\rfloor)(1-\lfloor x\rfloor)+\lfloor x\rfloor roof$,

where $\lfloor x\rfloor$ is the biggest integer less than $x$ (examples: $\lfloor 0,5\rfloor=\lfloor 0,9999\rfloor=0$, $\lfloor 6,5\rfloor=\lfloor 6,99999\rfloor=\lfloor 6\rfloor=6$ and so far).

Finally I think this is it! It works in my spreadsheet program. I guess it can be simplified but I don't dear touch it again.


Old "solution":

If you want a smooth function to fulfill your conditions you may use the unique second order polynomial with $p(0)=0$ as follows:

$p(x)=a\cdot x^2+b\cdot x+c$

(*) $p(0)=0\implies c=0$

$p(1/2)=1\implies \displaystyle\frac{a}{4}+\frac{b}{2}=1\implies a+2b=4$

$p(1)=roof\implies a+b=roof$,

why $b=4-roof$ and $a=roof-(4-roof)=2\cdot(roof-2)$

and therefore $p(x)=2\cdot(roof-2)\cdot x^2-(roof-4)\cdot x$.