Creating a user-defined log function

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

Is there a function that has the ability to compute a log function with a user / variable base? or perhaps there is an alternative way to fill in this formula.

The main idea of ​​my formula is log (1 + 0.02) (1.26825) (1 + 0.02 - base). That should be 12,000.

+6
source share
3 answers

Like this:

double logWithBase(double base, double x) { return log(x) / log(base); } 
+14
source

You can compute arbitrary logarithms with log b x = log c x / log c b , where c is one of the most accessible databases, such as 10 or e .

In your specific example, log e 1.26825 = 0.237637997 and log e 1.02 = 0.019802627 . This is 12.000 (within my accuracy of the calculator): 0.237637997 / 0.019802627 = 12.000326876 .

In fact, 1.02 12 is actually 1.268241795 and, if you use this value, you are approaching 12:

  • log e 1.268241795 = 0.237631528
  • log e 1.02 = 0.019802627
  • 0.237631528 / 0.019802627 = 12.000000197 .
+1
source

The beam is right, but there is a modification of the Obj-C method:

 -(double) logWithBase:(double)base andNumber:(double)x { return log(x) / log(base); } 
+1
source

Source: https://habr.com/ru/post/892549/


All Articles