Saturday, 3 June 2017

logarithms - Approximation $log_2(x)$



Can anyone share an easy way to approximate $\log_2(x)$, given $x$ is between $0$ and 1?



I'm trying to solve this using an old fashioned calculator (i.e. no logs)



Thanks!




EDIT: I realize that I stepped a bit ahead. The x comes in the form of a fraction, e.g. 3/8, which is indeed between 0 and 1, but could also be written as log2(3) - log2(8). I am hoping there is a quick way to approximate this calculation to let's say 2 decimals


Answer



First normalize the value to the range $[1,2)$, multiplying by $2$ as long as necessary (the number of multiplies will form the integer part of the logarithm).



Then use the formula



$$\log_2\left(\frac{1+t}{1-t}\right)=\frac2{\ln(2)}\left(t+\frac{t^3}3+\frac{t^5}5\cdots\right)$$ evaluating for



$$t=\frac{x-1}{x+1}$$which will be in range $[0,\dfrac13)$. It will converge reasonably quickly, about one correct decimal per term.







Another option is to keep a tabulated list of constants such as $1.5,1.25,1.125\cdots$ together with their logarithms, and use



$$x>C_i\to \log_2(x)=\log_2\left(\frac x{C_i}\right)+\log(C_i).$$



At the same time as you divide $x$ by the constants (but keeping $x>1$), you accumulate the logarithms of these constants. When $x\approx1$, you have it. You can choose the set of constants that suits you best.


No comments:

Post a Comment

real analysis - How to find $lim_{hrightarrow 0}frac{sin(ha)}{h}$

How to find $\lim_{h\rightarrow 0}\frac{\sin(ha)}{h}$ without lhopital rule? I know when I use lhopital I easy get $$ \lim_{h\rightarrow 0}...