Good approximation to $\ln(x)$ for $x$ in $1 < x < e$

2k Views Asked by At

I'm looking for a simple function that gives a good approximation to $\ln(x) $ within $1 < x < e$.

Do you have anything in mind? I'm not looking for an infinite function, but a short and finite version of it might be good, if it's also a simple solution as well.

5

There are 5 best solutions below

11
On BEST ANSWER

There is a simple approximation through the Cauchy-Schwarz inequality, $\log(x)\approx\sqrt{x}-\frac{1}{\sqrt{x}}$.

$$ \log(x)=\int_{1}^{x}\frac{dt}{t}\stackrel{CS}{\leq}\sqrt{\int_{1}^{x}1\,dt \int_{1}^{x}\frac{dt}{t^2}} = \sqrt{\frac{(x-1)^2}{x}}. $$ A better approximation is given by a Padé approximant at $x=1$,

$$ \log(x) \approx \frac{3x^2-3}{x^2+4x+1}.$$

We also have a technique allowing to convert a not-so-good approximation $f_1$ into a better approximation $f_2$: $$ f_2(x) = 1+\frac{1}{x}\left(-1+\int_{1}^{x}f_1(t)\,dt\right) $$ This tecnique produces, starting from $f_1(x)=\sqrt{x}-\frac{1}{\sqrt{x}}$, the following approximation that is comparable to the previous Padé approximant:

$$ \log(x) \approx \frac{\left(-1+\sqrt{x}\right) \left(-1+5 \sqrt{x}+2 x\right)}{3 x}$$

5
On

As $n \to \infty$, $ n(x^{1/n}-1) $ converges to $\log{x}$ from below, while $n(1-x^{-1/n})$ converges from above. Choose a large enough $n$ and you'll get a simple uniform approximation that you can make as accurate as you like.

1
On

Here are two approximations for the natural logarithm from K. Oldham & J. Spanier, An Atlas of Functions, 1st Ed., Ch. 25, Hemisphere.

$$\ln(x)\simeq\frac{x-1}{\sqrt{x}},\ \ \ \ 3/4\le x\le 4/3$$

$$\ln(x)\simeq (x-1)\left(\frac{6}{1+5x}\right)^{3/5},\ \ \ \ 1/2\le x\le 2$$

You can go up to $x=e$ with $\ln(x)=\ln(\sqrt{x})+\ln(\sqrt{x})$.

0
On

As explained in this answer, the following series can be deduced from the Taylor series of the hyperbolic arctangent:

$$\boxed{ \ln x = 2 \sum_{k \ge 0} \frac{1}{2k+1} \left( \frac{x-1}{x+1} \right)^{2k+1} }.$$

Truncating this series results in rational approximations to $\ln x$ which are not as good as the comparable Padé approximant but at least very straightforward to compute and much better than truncating the Taylor series around $x = 1$. For example the first term gives

$$\ln x \approx 2 \frac{x-1}{x+1}$$

while the first two terms gives

$$\ln x \approx 2 \left( \frac{x-1}{x+1} + \frac{1}{3} \left( \frac{x-1}{x+1} \right)^3 \right) = \frac{8(x^3 - 1)}{3(x + 1)^3}.$$

Let's compare the approximations given in the answers so far by seeing how well they do at approximating $\ln e - 1 = 0$. Jack's approximations give

$$\ln e - 1 \approx \sqrt{e} - \frac{1}{\sqrt{e}} - 1 \approx 0.0422 \dots $$ $$\ln e - 1 \approx \frac{3e^2 - 3}{e^2 + 4e + 1} - 1 \approx -0.00493 \dots $$ $$\ln e - 1 \approx \frac{\left(-1+\sqrt{e}\right) \left(-1+5 \sqrt{e}+2 e\right)}{3 e} - 1 \approx 0.00871 \dots $$

so the second two approximations gain an extra digit of accuracy compared to the first.

Chappers does not specify a value of $n$ so we'll test $n = 10, 100$. This gives

$$\ln e - 1 \approx 10(e^{1/10} - 1) - 1 \approx 0.0517 \dots $$ $$\ln e - 1 \approx 100(e^{1/100} - 1) - 1 \approx 0.00502 \dots $$

so $n = 100$ gives an approximation comparable to the Padé approximant but it requires computing $e^{1/100}$ whereas the Padé approximant itself only requires a few ordinary arithmetic operations.

Cye Waldman's second approximation, together with $\ln x = 2 \ln \sqrt{x}$, gives

$$\ln e - 1 \approx 2 (\sqrt{e} - 1) \left( \frac{6}{1 + 5 \sqrt{e}} \right)^{3/5} - 1 \approx 0.00109 \dots $$

so we do better than the Padé approximant but at the cost of needing to compute $\sqrt{e}$ and also that $(-)^{3/5}$. If we also allow the Padé approximant the courtesy of using the square root, we get

$$\ln e - 1 \approx 2 \frac{3e - 3}{e + 4 \sqrt{e} + 1} - 1 = -0.000337 \dots $$

so the Padé approximant is more accurate again and with fewer difficult operations. Finally, my approximations give

$$\ln e - 1 \approx 2 \frac{e-1}{e+1} - 1 \approx -0.0758 \dots $$ $$\ln e - 1 \approx \frac{8(e^3 - 1)}{3(e + 1)^3} - 1 \approx -0.00997 \dots $$

so the first two terms are comparable to but a bit worse than the Padé approximant.

Overall the Padé approximant clearly wins for accuracy vs. ease of computation. Keep in mind that there are more! WolframAlpha tells us that the cubic approximant is

$$\ln x \approx \frac{11x^3 + 27x^2 - 27x - 11}{3x^3 + 27x^2 + 27x + 3}$$

which gives

$$\ln e - 1 \approx \frac{11e^3 + 27e^2 - 27e - 11}{3e^3 + 27e^2 + 27e + 3} - 1 \approx -0.000306 \dots $$

which is the best approximation so far and still doesn't require square roots or similar.

0
On

Here are two approximations from my notes, which unfortunately do not preserve how I generated them. I do recall puzzling around, starting out from $$\ln x \approx 2\frac{x-1}{x+1}$$ I was looking for approximations requiring a very small number of elementary mathematical operations, and in particular also taking advantage of fused multiply-add. The first approximation is $$ f_{1}(x) := 1.84195 - \frac{5.625}{2x+1} $$ which has a maximal absolute error $|f_{1}(x) - \ln x| < 0.03305$ on $[1, e]$. The second approximation is $$ f_{2}(x) := \frac{5x+3\sqrt{e}}{2(x+\sqrt{e})}$$ with $|f_{2}(x) - \ln x| < 0.01017$ on $[1, e].$ In practical terms, $\sqrt{e}$ and $3\sqrt{e}$ can be precomputed, making $f_{2}$ minimally more computationally intensive than $f_{1}$. A close to minimax rational approximation is $$f_{3}(x) := \frac{324x-323}{128x+211}$$ with $|f_{3}(x) - \ln x| < 0.00296$ on $[1,e]$.