1

I have an upper and lower bound number:

upper: 21

lower: 3

I then have a second number that can be anywhere between this range, I would like the second number to increment faster when it is closer to the lower bound and slower when it is closer to the upper bound.

How can I achieve this using mathematics?

EDIT: I am developing a mapping application using google maps, I have 2 constants (MAX ZOOM / MIN ZOOM) and 1 variable (CURRENT ZOOM LEVEL). I draw a circle on the map and would like the radius of it to increase based on the current zoom level. So When the current zoom level is closer to the MAX ZOOM, the radius increase is smaller than when the current zoom level is closer to the MIN ZOOM.

I hope this clarifies what I am trying to achieve.

S-K'
  • 115
  • Do you simply mean that you want an increasing function on the closed interval $[3,21]$--or perhaps the open interval $(3,21)$--that increases less and less quickly as we near the upper endpoint? – Cameron Buie Aug 19 '13 at 20:24
  • @S-K' Do you imagine your point moving up in jumps towards 21 or do you imagine it moving along a line towards 21 but getting slower the closer it gets? – JH92 Aug 19 '13 at 21:08
  • It would move up in jumps towards 21 – S-K' Aug 20 '13 at 09:14
  • @S-K' OK, see my answer below, and look at the final equation. Tag me in a comment if there is something you don't understand or it wasn't what you wanted. – JH92 Aug 20 '13 at 11:15
  • @user84751 please see my update – S-K' Aug 20 '13 at 11:33
  • @S-K' I think I get you, but it seems like you want the radius to increase only once, but based on the current zoom level. Just to give me an idea.. If your current zoom level was at 10, what would you want it to increase to? What if it was at 15, 20? – JH92 Aug 20 '13 at 11:53
  • @S-K' Suppose x is your chosen zoom level. Can you set Change in Radius = K(21-x), where K is a constant of your choice? This isn't the only way to do it but it might work..? – JH92 Aug 20 '13 at 12:02
  • @user84751 Clicking the circle will increase the radius multiple times, I have K(21-x) currently and it does not work too well when x is nearer the MIN ZOOM LEVEL. I think as X gets smaller the change in radius needs to increase. – S-K' Aug 20 '13 at 12:12
  • @S-K' Try using powers, and see what works out best, for example K(21-x)^1.5. This will increase relatively quicker at lower x's. – JH92 Aug 20 '13 at 12:40
  • Could you edit your answer with this? Thanks for the help :) – S-K' Aug 20 '13 at 12:41
  • @S-K' Paragraph added at the end. No problem :) – JH92 Aug 20 '13 at 14:17

2 Answers2

2

Suppose that the second number moves along the real number line between 3 and 21. We want its speed to be higher when it is close to 3, and lower when it is close to 21, but always moving upwards. I assume you don't want it to pass 21 (or ever quite reach it for that matter).

So, let x(t) be the position of the second number at time t. Where it starts is x(0), and we will call this number K and let it lie anywhere on the half-open interval [3,21). As x(t) increases, we want the velocity of the second number to decrease. One way to model this would be:

Velocity (t) = 21 - x(t).

Notice, the point will always move upwards towards 21, and would stop if it ever reached it.

Now, the velocity of the point is the rate of change of its position with respect to time. What we have is thus a differential equation:

dx/dt = 21 - x(t)

If you have any experience with these equations, you will find that the solution to this equation is found by separating variables and is given by:

x(t) = 21 - (21-K)*e^(-t), where K is the place the second point started off.

Whether you consider time to move in discrete jumps, ie. t=0,1,2,3,4... , or you consider time to evolve continuosly as a real number, the last equation should do what you ask for.

In light of your edit and comments, notice that for y>1, and x<20, you are guaranteed that K(21-x)^y will give a greater rate of change in your radius with respect to a change in x than will K(21-x). For small x's, the rate of change will be even greater still, as you required. The mathematical reason for this is that the second derivative of K(21-x)^y wrt -x is positive. Have a think! Drawing a graph will make it much more obvious..

JH92
  • 213
0

The notion of how quickly a function changes, in the language of sufficiently smooth functions, is called its derivative. If $f$ is the function, we will write $f'$ for its derivative.

Note that from here on out, I will be using the function as follows. If $x$ is the input number, then $f(x)$ is the second number.

Using this terminology, you want a function with large derivative at small numbers, and small derivative at large numbers. In other words, you want the function's derivative to be decreasing.

We have a large supply of decreasing functions: we could consider a line, for instance, or perhaps a segment of $\frac1x$. Or we could use some combination of these.

The only other restriction is that $f$ must be increasing, that is $f(x)\geq x$. Since $f(x)\leq 21$, this means that $f(21)=21$. In the general vicinity of 21, we probably want the function to not affect numbers too much, for smoothness reasons. The easiest way to achieve this is to make $f'(21)=0$.

Thus, we have reduced the problem to the following differential equation. Suppose that $\tilde D$ is our favorite decreasing function. Manipulate $\tilde D$ to become $D$ such that $D(21)=0$; this can be achieved always by shifting up/down $D(x)=\tilde D(x)+a$ for some constant $a$, or in some cases more desirable behavior is obtained by expanding/compressing $D(x) = b\cdot\tilde D(x)$ for some constant $b$. (Note that $a$ and $b$ are not arbitrary; they must be chosen correctly to get the desired outcome) From there, the constraints are to find an $f$ such that $$f'(x)=D(x) ~~~~~~~~~~~~ f(21)=21$$

After choosing the desired $\tilde D$ and the appropriate manipulation, the problem can be solved using your favorite numerical or symbolic integrator, for example, Wolfram Alpha.

Eric Stucky
  • 12,758
  • 3
  • 38
  • 69