Concept
How can the logarithm of a number be computed in an arbitrary base?
ComputerScienceOne / Computing a Logarithm
"16.3. Examples 16.3.1. Computing a Logarithm The logarithm of x is the exponent that some base must be raised to get x. The most common logarithm is the natural logarithm, ln(x) which is base e = 2.71828.... But logarithms can be in any base b > 1. What if we wanted to compute log₂(x)? Or logπ(x)? Let’s write a program that will prompt the user for a number x and a base b and computes log_b(x). Arbitrary bases can be computed using the change of base formula: log_b(x) = log_a(x) / log_a(b). If we can compute some base a, then we can compute any base b. Fortunately we have such a solution. Recall that the standard library provides a function to compute the natural logarithm, log(). This is one of the fundamentals of problems solving: if a solution already exists, use it. In this case, a solution exists for a different, but similar problem (computing the natural logarithm), but we can adapt the solution using the change of base formula. In particular, if we have variables b (base) and x, we can compute log_b(x) using"
Related Ideas
- How can a Java program compute a logarithm in an arbitrary base?ComputerScienceOne · Computing a Logarithm
- How can conditionals validate input for a logarithm calculator?ComputerScienceOne · Quadratic Roots Revisited
- How can conditionals validate logarithm inputs and handle errors?ComputerScienceOne · Life & Taxes
- How can conditionals and the change of base formula validate logarithm input in PHP?ComputerScienceOne · Life & Taxes
- How do you use the C standard mathematics library?ComputerScienceOne · Preprocessor Directives