Algorithms – Calculating Non-Integer Exponent

algorithmsproblem solving

I just wanted to directly calculate the value of the number $2^{3.1}$ as I was wondering how a computer would do it. I've done some higher mathematics, but I'm very unsure of what I would do to solve this algorithmically, without a simple trial and error.

I noted that

$$ 2^{3.1} = 2^{3} \times 2^{0.1} $$

So I've simplified the problem to an "integer part" (which is easy enough) : $2^3 = 2\times 2\times 2$, but I'm still very confused about the "decimal part". I also know that :

$$ 2^{0.1} = e^{0.1\log{2}} $$

But that still presents a similar problem, because you'd need to calculate another non-integer exponent for the natural exponential. As far as I can see, the only way to do this is to let:

$$2^{0.1}=a $$

And then trial and error with some brute force approach (adjusting my guess for a as I go). Even Newton's method didn't seem to give me anything meaningful. Does anybody have any idea how we could calculate this with some working algorithm?

Best Answer

Start with:

$$2^{3.1} = 2^3 2^{0.1} = 2^3 e^{0.1 \log{2}}$$

Now use a Taylor expansion, so that the above is approximately

$$2^3 \left [1+0.1 \log{2} + \frac{1}{2!} (0.1 \log{2})^2 + \frac{1}{3!} (0.1 \log{2})^3+\cdots + \frac{1}{n!} (0.1 \log{2})^n\right ] $$

wheer $n$ depends on the tolerance you require. In this case, if this error tolerance is $\epsilon$, then we want

$$\frac{1}{(n+1)!} (0.1 \log{2})^{n+1} \lt \epsilon$$

For example, if $\epsilon=5 \cdot 10^{-7}$, then $n=4$.

Related Question