logarithm

How can I specify the base for Math.log() in JavaScript?

爱⌒轻易说出口 提交于 2019-11-26 08:42:54
问题 I need a log function for JavaScript, but it needs to be base 10. I can\'t see any listing for this, so I\'m assuming it\'s not possible. Are there any math wizards out there who know a solution for this? 回答1: "Change of Base" Formula / Identity The numerical value for logarithm to the base 10 can be calculated with the following identity. Since Math.log(x) in JavaScript returns the natural logarithm of x (same as ln(x) ), for base 10 you can divide by Math.log(10) (same as ln(10) ): function

What would cause an algorithm to have O(log log n) complexity?

柔情痞子 提交于 2019-11-26 06:54:47
问题 This earlier question addresses some of the factors that might cause an algorithm to have O(log n) complexity. What would cause an algorithm to have time complexity O(log log n)? 回答1: O(log log n) terms can show up in a variety of different places, but there are typically two main routes that will arrive at this runtime. Shrinking by a Square Root As mentioned in the answer to the linked question, a common way for an algorithm to have time complexity O(log n) is for that algorithm to work by

What would cause an algorithm to have O(log n) complexity?

☆樱花仙子☆ 提交于 2019-11-26 06:52:06
问题 My knowledge of big-O is limited, and when log terms show up in the equation it throws me off even more. Can someone maybe explain to me in simple terms what a O(log n) algorithm is? Where does the logarithm come from? This specifically came up when I was trying to solve this midterm practice question: Let X(1..n) and Y(1..n) contain two lists of integers, each sorted in nondecreasing order. Give an O(log n)-time algorithm to find the median (or the nth smallest integer) of all 2n combined

Plot logarithmic axes with matplotlib in python

ぃ、小莉子 提交于 2019-11-26 06:01:04
I want to plot a graph with one logarithmic axis using matplotlib. I've been reading the docs, but can't figure out the syntax. I know that it's probably something simple like 'scale=linear' in the plot arguments, but I can't seem to get it right Sample program: import pylab import matplotlib.pyplot as plt a = [pow(10, i) for i in range(10)] fig = plt.figure() ax = fig.add_subplot(2, 1, 1) line, = ax.plot(a, color='blue', lw=2) pylab.show() Mathieu You can use the Axes.set_yscale method. That allows you to change the scale after the Axes object is created. That would also allow you to build a

Building a logarithm function in C without using float type

柔情痞子 提交于 2019-11-26 05:58:49
问题 I need to rewrite the log function (base 2 or base 10 doesn\'t matter which) without using float type, but I need to get the precision of few decimal digits after the decimal point. ( like a float * 100 to get 2 decimals inside integer type eg: if the 1.4352 would be the result, my function should return something like 143 ( int type) and I know that the last 2 numbers are the decimals. I found over the stackoverflow some methods like: How can I compute a base 2 logarithm without using the

What is the difference between 'log' and 'symlog'?

旧街凉风 提交于 2019-11-26 04:10:57
问题 In matplotlib, I can set the axis scaling using either pyplot.xscale() or Axes.set_xscale(). Both functions accept three different scales: \'linear\' | \'log\' | \'symlog\' . What is the difference between \'log\' and \'symlog\' ? In a simple test I did, they both looked exactly the same. I know the documentation says they accept different parameters, but I still don\'t understand the difference between them. Can someone please explain it? The answer will be the best if it has some sample

Efficient implementation of log2(__m256d) in AVX2

落花浮王杯 提交于 2019-11-26 03:59:24
问题 SVML\'s __m256d _mm256_log2_pd (__m256d a) is not available on other compilers than Intel, and they say its performance is handicapped on AMD processors. There are some implementations on the internet referred in AVX log intrinsics (_mm256_log_ps) missing in g++-4.8? and SIMD math libraries for SSE and AVX , however they seem to be more SSE than AVX2. There\'s also Agner Fog\'s vector library , however it\'s a large library having much more stuff that just vector log2, so from the

Logarithm of a BigDecimal

亡梦爱人 提交于 2019-11-26 02:57:19
问题 How can I calculate the logarithm of a BigDecimal? Does anyone know of any algorithms I can use? My googling so far has come up with the (useless) idea of just converting to a double and using Math.log. I will provide the precision of the answer required. edit: any base will do. If it\'s easier in base x, I\'ll do that. 回答1: Java Number Cruncher: The Java Programmer's Guide to Numerical Computing provides a solution using Newton's Method. Source code from the book is available here. The

How to do an integer log2() in C++?

流过昼夜 提交于 2019-11-26 02:56:27
问题 In the C++ standard libraries I found only a floating point log method. Now I use log to find the level of an index in a binary tree ( floor(2log(index)) ). Code (C++): int targetlevel = int(log(index)/log(2)); I am afraid that for some of the edge elements (the elements with value 2^n) log will return n-1.999999999999 instead of n.0. Is this fear correct? How can I modify my statement so that it always will return a correct answer? 回答1: You can use this method instead: int targetlevel = 0;

Plot logarithmic axes with matplotlib in python

流过昼夜 提交于 2019-11-26 01:51:13
问题 I want to plot a graph with one logarithmic axis using matplotlib. I\'ve been reading the docs, but can\'t figure out the syntax. I know that it\'s probably something simple like \'scale=linear\' in the plot arguments, but I can\'t seem to get it right Sample program: import pylab import matplotlib.pyplot as plt a = [pow(10, i) for i in range(10)] fig = plt.figure() ax = fig.add_subplot(2, 1, 1) line, = ax.plot(a, color=\'blue\', lw=2) pylab.show() 回答1: You can use the Axes.set_yscale method.