0

I need a way to create an exponential function where the output is limited from 0.90 to 1 based on a range of numbers.

For example i have the following range: [1000, 1001, ...1400]

Now when the input is 1000, the output should be 0.90, but when the input is 1400 the output should be 1. Any number in between should be exponential closer to 1 based on the number in the range.

I have come up with this function to create an output of 0 to 1 exponentially based on the range:

$$ f(x) =((x-s)/(e-s))^a $$

  • $x$ = the current number
  • $s$ = The first number in the range
  • $e$ = The last number in the range
  • $a$ = the power for the exponential curve

How can i limit the output to start from 0.9 to 1? Instead of 0 to 1?

Eddy
  • 1,139
  • 7
  • 12
  • Your provided function is a power law, not an exponential. What is it you want? – Eddy Dec 10 '17 at 18:44
  • @Eddy What i want is to take a percentage of $x$ where i start with 10% of the inititial value ($s$), now when $x$ moves on closer to the last number ($e$) i want to take less percentage of $x$ and so when $x$ equals to $e$ i want to take 0% of the $x$. I want this range of percentages from 10 to 0 to be exponential. So how closer $x$ is to $e$ how less percentage i want to take from. – Skywalker Dec 10 '17 at 18:58

2 Answers2

0

We wish to find the values of $a$ and $b$ such that the function $$ f(x) = a e^{bx} $$ satisfies $$ f(x_0)=f_0 \quad f(x_1)=f_1 $$ thus $$ a e^{bx_0}= f_0 \quad a e^{bx_1}= f_1 $$

Dividing the two expressions $$ \frac{e^{bx_0}} {e^{bx_1}} = \frac{f_0} {f_1} $$ $$ b = \frac{\ln(f_0) - \ln(f_1)} {x_0-x_1} $$

Taking the log of each $$ \ln(a) + bx_0= \ln(f_0) \quad \ln(a) + bx_1= \ln(f_1) $$ $$ b=\frac{\ln(f_0)-\ln(a)} {x_0} \quad b=\frac{\ln(f_1)-\ln(a)} {x_1} $$ $$ \frac{\ln(f_0)-\ln(a)} {x_0}=\frac{\ln(f_1)-\ln(a)} {x_1} $$ $$ \ln(a) (x_1-x_0) = x_1 \ln(f_0) - x_0 \ln(f_1) $$ $$ a=\exp\left(\frac{x_1 \ln(f_0) - x_0 \ln(f_1)} {x_1-x_0} \right) $$ Thus the function is $$ f(x) = \exp\left(\frac{x_1 \ln(f_0) - x_0 \ln(f_1)} {x_1-x_0} + \frac{\ln(f_0) - \ln(f_1)} {x_0-x_1}x\right) $$ $$ f(x) = \exp\left(\frac{(x_1-x) \ln(f_0) + (x-x_0) \ln(f_1)} {x_1-x_0} \right) $$ You may choose any domain $(x_0,x_1) $ and corosponding function values $f_0$ and $f_1$.

Eddy
  • 1,139
  • 7
  • 12
  • Thank you very much sir, this is almost exactly what i need. My only question is how do i get a curve in the output? When it plot this it is a straight line. – Skywalker Dec 17 '17 at 18:58
  • Did you forget to use the exponential? – Eddy Dec 17 '17 at 20:20
  • No i did use the exp. Don't get me wrong it is an exponential outcome, but how can i make it more curved? Right now its a straight line. – Skywalker Dec 17 '17 at 20:32
  • If you want an exponential then that is the unique exponential that passes through your 2 points. If you want a general curve then I can put together an answer for the general case. – Eddy Dec 17 '17 at 20:33
  • I would like an adjustable curve, some number i can change ti determine the curve. If you would like to create a new answer for the curve that would be very much appriciated! This function right now is greate except its not curved or curvable. Thank you very much. – Skywalker Dec 17 '17 at 20:39
0

In response to a conversation in the comments on my other answer, here is an answer for a more general case.

We wish to rescale the coordinates for an invertible function $g$ so that the function values at two points are those chosen. That is we define $$ f(x) = g(ax+b) $$ Where $a$ and $b$ will be chosen so that $$ f(x_0) = f_0 \quad f(x_1) = f_1 $$ Thus $$ ax_0+b= g^{-1} (f_0) \quad ax_1+b= g^{-1} (f_1) $$ Thus $$ a(x_1-x_0) = g^{-1} (f_1) - g^{-1} (f_0) $$ $$ a = \frac{g^{-1} (f_1) - g^{-1} (f_0)}{x_1-x_0} $$ and $$ \frac{b}{x_0}-\frac{b}{x_1}=\frac{g^{-1} (f_0)}{x_0}-\frac{g^{-1} (f_1)}{x_1} $$ $$ b=\frac{x_1g^{-1} (f_0)-x_0g^{-1} (f_1)}{x_1-x_0} $$ Substituting for $a$ and $b$ $$ f(x) = g\left(\frac{g^{-1} (f_1) - g^{-1} (f_0)}{x_1-x_0}x+\frac{x_1g^{-1} (f_0)-x_0g^{-1} (f_1)}{x_1-x_0}\right) =g\left( \frac{(x-x_0)g^{-1} (f_1) + (x_1-x) g^{-1} (f_0)} {x_1-x_0} \right) $$

At this stage we can consider various choices for $g$. For example, exponential up to a constant $$ g(x) = \exp(x)+c $$ $$ f(x) =\exp\left( \frac{(x-x_0)\ln(f_1-c) + (x_1-x) \ln(f_0-c)} {x_1-x_0} \right) +c $$ and power law up to a constant $$ g(x) =x^p+c $$ $$ f(x) =\left( \frac{(x-x_0)(f_1-c)^{1/p} + (x_1-x) (f_0-c)^{1/p}} {x_1-x_0} \right) ^p+c $$

Eddy
  • 1,139
  • 7
  • 12
  • This seems right, although i can't seem get a nice curve, it only curves a little bit in the beginning (or end when using negative numbers) – Skywalker Dec 17 '17 at 21:41
  • Added another free parameter for you to play with, but you can always choose your own $g$ – Eddy Dec 17 '17 at 21:49
  • Im sorry but unless i am doing something wrong, it is still a straight line. The power law only seems to move the beginning of the line on its Y axis. For the $c$ parameter its only moving the line as a whole in its Y axis.

    See this: https://www.desmos.com/calculator/3pvtwlfvjp

    – Skywalker Dec 17 '17 at 22:05
  • Have you tried $p=100$ – Eddy Dec 17 '17 at 22:09
  • Yes, it doesn't seem to change much. Please check out this link to see how i am plotting the graph: https://www.desmos.com/calculator/fffjeg0iqb – Skywalker Dec 17 '17 at 22:18
  • I don't know how to edit the plot you've sent, but you haven't plotted the function in my answer. There's a power of $p$ missing – Eddy Dec 17 '17 at 22:29
  • Also, you seem to be plotting $xf(x)$ not $f(x)$ – Eddy Dec 17 '17 at 22:32
  • I am sorry, i indeed forgot $p$ in this graph, but it still doesnt make much of a change. I am plotting $g(x,i)$ which is just $x*i$ where $i$ equals the answer from $f(x)$. Anyways, to edit the function i think you can just click on one of the 'items' to start typing. There is also a share button on the right top corner. – Skywalker Dec 17 '17 at 22:38
  • Well, if you don't want something proportional to $x$, then $f(x) $ would be a better function than $g(x) =xf(x)$ If you want the plot to be at a better aspect ratio then try $g(x) =1000f(x)$ – Eddy Dec 17 '17 at 22:44
  • I think $xf(x)$ is the right thing, $1000f(x)$ seems to mess it up, anyways: here is the working graph with the right power $p$: https://www.desmos.com/calculator/t5nexdeco5 – Skywalker Dec 17 '17 at 22:54
  • Have you tried it with $c$ in as well? Say $c=0.9$? – Eddy Dec 17 '17 at 22:57
  • And when I plotted $1000f(x)$ the plotter worked and plotted the correct function. $xf(x) $ is DEFINITELY wrong – Eddy Dec 17 '17 at 22:58
  • I think we have some miscommunication. Please take a look at this image: https://ibb.co/kfKb4m and lets get back a few steps. Your first answer was almost good, it gave me the purple plot (indeed when using $xf(x)$ but this is what i need). Now what i want is the green and/or orange curved line. I think mathematically they are both different but at least one of these two which is editable with a parameter would be nice – Skywalker Dec 17 '17 at 23:18
  • That link doesn't work – Eddy Dec 17 '17 at 23:26
  • If it gave a 502 error, it should work after some refreshes. I think their server was down for a minute. – Skywalker Dec 17 '17 at 23:28
  • Neither of your plots is obtainable for a function $g(x)=xf(x)$ where $f(x)$ is monotonic. Try plotting either of my provided functions, that is $f(x)$, with $(x_0,f_0)=(1000,900)$, $(x_1,f_1)=(1400,1400)$. For the exponential try values of $0<c<800$, for the power law $0<c<900$, $1<p$. – Eddy Dec 18 '17 at 13:22
  • Also, please accept my answer as I have more than answered your original question. – Eddy Dec 18 '17 at 13:23
  • Thank you very much, you were right about the answer. I finally got it working. How can i ever repay you for your effort? – Skywalker Dec 18 '17 at 15:14