Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a log function with a custom base

I have a formula and this formula uses a log function with a custom base for example log with a base of b and value of x. In objective-c, I know there are log functions that calculate without a base and base of either 2 or 10.

Is there a function that has the ability to calculate a log function with a custom/variable base? or maybe there is an alternative method of completing this formula.

The basic idea of my formula is this log(1+0.02)(1.26825) (1+0.02 is the base). This should equal 12.000.

like image 903
Peter DeMartini Avatar asked Jul 12 '11 05:07

Peter DeMartini


People also ask

How do you add a base to a logarithm?

Logs of the same base can be added together by multiplying their arguments: log(xy) = log(x) + log(y). They can be subtracted by dividing the arguments: log(x/y) = log(x) - log(y).

Can the base of log be a function?

To understand why, we have to understand that logarithms are actually like exponents: the base of a logarithm is also the base of a power function.


1 Answers

Like this:

double logWithBase(double base, double x) {
    return log(x) / log(base);
}
like image 132
Ray Toal Avatar answered Sep 19 '22 17:09

Ray Toal