How to generate $\log$ function that intersects at $(0,1)$ and $(1,0)$?

I apologize for any incorrect or missing formatting, first time posting in the math stack exchange. It's been a few years since I've done any kind of calculus, so I remember nothing at all, which is probably the reason why I find my self stumped so early in my calculations.

I'm looking to generate a logarithmic algorithm that will follow a plot that will pass the following points: $(0,1)$ and $(1,0)$. My end goal is to generate a programming function that will return a very simple repulsion force ceofficient value based on a distance between two points. I would like, however, that the force drop (logarithmic?) the further these two points are, and grow (exponentially?) the closer they get. This is in no way an accurate calculation I'm looking for, but merely a non-linear function to return me a scalar coefficient between 0 and 1 that I can manipulate later on.

I want the function to cross at $(1,0)$ and $(0,1)$ so I get a coefficient between $0$ and $1$. In my function, any Y value lower than $0$ will be floored at $0$ and likewise for $Y$ values over $1$ (where $x < 0$, which is possible since my $X$ value in my algorithm will likely be an offsetted value of the distance between two points).

That being said, with the following few assumptions:

1. $y = 0$ when $x = 1$
2. $y = 1$ when $x = 0$
3. $y < 0$ when $x > 1$
4. $y > 1$ when $x < 0$
5. $y = Alog(x + B) + C$
6. assuming log is log based 10

I tried to deduce the $A, B, C$ constants in order to generate a formula.

Here is what I've done so far:

1. From assumption #1, I can generate $1 = Alog(B) + C$
2. From assumption #2, I can generate $0 = Alog(1+B)+C$
3. I make both equations equals by transforming equation from 1. to $0 = Alog(B) + C -1$
4. Making the following equality: $Alog(B) + C - 1 = Alog(1+B) + C$
5. I can scratch both $C$ constants out (is it safe to assume $C=0$, or $C$ can be equal to any arbitrary value, without changing the equation's plot?): $Alog(B) - 1 = Alog(1+B)$
6. Dividing each part by A gets me: $\dfrac{Alog(B)}{A} - \dfrac{1}{A} = \dfrac{Alog(1+B)}{A}$
7. Allowing me to reduce both logs: $\log(B) - \dfrac{1}{A} = log(1+B)$
8. If I put both logs on the same side: $log(B) - log(1+B) = \dfrac{1}{A}$
9. I can combine them into: $\log(\dfrac{B}{1+B}) = \dfrac{1}{A}$

And I'd say this is where I'm stuck; I have two unknowns ($A$ and $B$) with one equation to solve. I don't know where to go from here. What's the next step?

If you have the functional form $f(x)=A\log (x+B)+C$ (with three parameters), and impose only the two constraints $f(0)=1$ and $f(1)=0$, then your problem is underdetermined and you should expect to have a free parameter remaining. What you've done so far is correct. $$f(0)=A\log B + C = 1 \\ f(1)=A\log(1+B)+C=0.$$ Subtracting one equation from the other gives $$A\log\frac{B}{1+B}=1$$ or $A=1/\log(B/(1+B)),$ and $C=-A\log(1+B)=-\log(1+B)/\log(B/(1+B)).$ You are free to choose $B$ as you like and then solve for $A$ and $C$.

For instance, let $B=1$. Then $A=1/\log(1/2)=-1/\log 2$ and $C=-\log 2/\log(1/2)=1$, so your function is $$f(x)=-\frac{\log(x+1)}{\log 2}+1=1-\log_2(x+1)=\log_2\left(\frac{2}{x+1}\right)=1-\log_{2}(x+1),$$ which you can readily see meets your constraints and is logarithmic. Or, let $B=1/9$. Then $A=-1$ and $C=\log_{10}(10/9)=1-\log_{10}9$, so $$f(x)=-\log_{10}\left(x+\frac{1}{9}\right)+1-\log_{10}9=1-\log_{10}(9x+1).$$ As you can see, a nice parameterization of the entire family of solutions is $$f_{\beta}(x)=1-\log_{\beta+1}\left(\beta x + 1\right),$$ valid for any positive $\beta$.

The answer is that each choice of $A, B, C$ that satisfy the conditions you've produced will give you a transformed log function that satisfies your conditions, and there are many such choices of $A, B, C$ that do this. That doesn't mean that we can set any particular variable to any value, however; for example, since $\log$ is increasing,

$\frac{1}{A} = \log \left(\frac{B}{1 + B}\right) < \log 1 = 0$

(but it turns out we can take $A$ to be any negative number, and this parametrizes all of the functions that satisfy your constraint).

As an aside, let me point out that attraction-repulsion laws in nature generally don't take such a form, but that's a separate issue from the mathematics itself.

• I've edited the question to explain that a this is no way a representative calculation of natural attraction-repulsion, but a simple calculation that can produce for me a coefficient that I can use to assure that two objects will try to repulse at small distances. – Prusprus Aug 25 '14 at 14:58

I suggest that you instead use

$$y=\frac{1}{(x+1)^{13}}$$

You can change the exponent $13$ so as to modify the shape.

This gives the correct sort of behaviour, it is significantly faster to evaluate computationally than logarithms, and it is physically more realistic (when you push real atoms together they repel with a force $\sim r^{-13}$).

• Sorry, for the confusion. It's the first time I write a 'physics' algorithm, so I base myself on the cause/effect I see on screen to understand what I'm doing - surely my terminology isn't correct. Y will be the force coefficient, which I will force between 0 and 1 by placing the floor at 0 and the ceiling at 1 on its value. I'm not so much looking for a vectorial value; rather, simply just a scalar value that I can later implement in the directions I wish. I am therefore running this logarithmic function twice, one for the dX and another for the dY, to get both X and Y force coefficients. – Prusprus Aug 25 '14 at 14:45
• As for the logarithm function, there may be a different function that may give me a similar result, I just don't know what these are. What I like about the log function is that it would give me a slope that is more aggressive the closer I approach of x = 0, x being the distance between two given points. – Prusprus Aug 25 '14 at 14:48
• @Prusprus If $y(0)=1$ then you're not going to see any 'aggressive' increase in the slope. – lemon Aug 25 '14 at 14:49
• @Prusprus I strongly recommend that you try the Lennard-Jones functional form. – lemon Aug 25 '14 at 14:50
• wolframalpha.com/input/… – lemon Aug 25 '14 at 14:55