logarithm

Using log base 10 in a formula in Java

无人久伴 提交于 2019-11-30 21:27:09
问题 I'm trying to write a Java program that can take values and put them into a formula involving log base 10. How can I calculate log 10 in Java? 回答1: It looks like Java actually has a log10 function: Math.log10(x) Otherwise, just use math: Math.log(x) / Math.log(10) http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html 回答2: Math.log10(x) suffices for floating-point numbers. If you need integer log base 10, and you can use third-party libraries, Guava provides IntMath.log10(int,

Compile time computing of number of bits needed to encode n different states

淺唱寂寞╮ 提交于 2019-11-30 18:55:12
Edit: In the initial question had a wrong formula and the algorithm tried was doing something completely different than what was intended. I apologise and I decided to rewrite the question to eliminate all the confusion. I need to compute at compile time (the result will be used as a non-type template parameter) the minimum number of bits needed to store n different states: constexpr unsigned bitsNeeded(unsigned n); or via template The results should be: +-----------+--------+ | number of | bits | | states | needed | +-----------+--------+ | 0 | 0 | * or not defined | | | | 1 | 0 | | | | | 2 |

Non-linear axes for imshow in matplotlib

旧时模样 提交于 2019-11-30 17:54:41
I am generating 2D arrays on log-spaced axes (for instance, the x pixel coordinates are generated using logspace(log10(0.95), log10(2.08), n) . I want to display the image using a plain old imshow, in its native resolution and scaling (I don't need to stretch it ; the data itself is already log scaled), but I want to add ticks, labels, lines that are in the correct place on the log axes. How do I do this? Ideally I could just use commands line axvline(1.5) and the line would be in the correct place (58% from the left), but if the only way is to manually translate between logscale coordinates

Labelling logarithmic scale display in R

谁说胖子不能爱 提交于 2019-11-30 11:42:22
While plotting histogarm, scatterplots and other plots with axes scaled to logarithmic scale in R, how is it possible to use labels such as 10^-1 10^0 10^1 10^2 10^3 and so on instead of the axes showing just -1, 0, 1, 2, 3 etc. What parameters should be added to the commands such as hist(), plot() etc? Joris Meys Apart from the solution of ggplot2 (see gsk3's comment), I would like to add that this happens automatically in plot() as well when using the correct arguments, eg : x <- 1:10 y <- exp(1:10) plot(x,y,log="y") You can use the parameter log="x" for the X axis, or log="xy" for both. If

Make y-axis logarithmic in histogram using R [duplicate]

 ̄綄美尐妖づ 提交于 2019-11-30 08:49:16
This question already has an answer here: Histogram with Logarithmic Scale and custom breaks 7 answers Hi I'm making histogram using R, but the number of Y axis is so large that I need to turn it into logarithmic.See below my script: hplot<-read.table("libl") hplot pdf("first_end") hist(hplot$V1, breaks=24, xlim=c(0,250000000), ylim=c(0,2000000),main="first end mapping", xlab="Coordinates") dev.off() So how should I change my script? thx You can save the histogram data to tweak it before plotting: set.seed(12345) x = rnorm(1000) hist.data = hist(x, plot=F) hist.data$counts = log10(hist.data

Finding the exponent of n = 2**x using bitwise operations [logarithm in base 2 of n]

家住魔仙堡 提交于 2019-11-30 08:44:24
Is there a straightforward way to extracting the exponent from a power of 2 using bitwise operations only? EDIT: Although the question was originally about bitwise operations, the thread is a good read also if you are wondering "What's the fastest way to find X given Y = 2 X in Python ?"** I am currently trying to optimize a routine ( Rabin-Miller primality test ) that reduces an even number N in the forms 2**s * d . I can get the 2**s part by: two_power_s = N & -N but I can't find a way to extract just " s " with a bitwise operation. Workarounds I am currently testing without too much

Logarithm function of an arbitrary integer base in C

早过忘川 提交于 2019-11-30 08:40:16
Is there a function or any other way to calculate in C the logarithm of base x , where x is an integer variable of my program? C doesn't provide functions to compute logarithms of any bases other than e or 10 . So just use math: logarithm of x base b = log(x)/log(b) If you'll be doing the logarithms over the same base repeatedly, you can precompute 1/log(b) . I wouldn't rely on the compiler being able to do this optimization for you. 来源: https://stackoverflow.com/questions/11054740/logarithm-function-of-an-arbitrary-integer-base-in-c

I need help proving that if f(n) = O(g(n)) implies 2^(f(n)) = O(2^g(n)))

我的梦境 提交于 2019-11-30 07:04:54
In a previous problem, I showed (hopefully correctly) that f(n) = O(g(n)) implies lg(f(n)) = O(lg(g(n))) with sufficient conditions (e.g., lg(g(n)) >= 1, f(n) >= 1 , and sufficiently large n). Now, I need to prove OR disprove that f(n) = O(g(n)) implies 2^(f(n)) = O(2^g(n))) . Intuitively, this makes sense, so I figured I could prove it with help from the previous theorem. I noticed that f(n) can be rewritten as lg(2^f(n)) and that g(n) is just lg(2^g(n)) , which got me excited...this is taking the log base 2 of both sides of what I want to prove, and it simplifies things a lot! But I'm pretty

Difference between O(n) and O(log(n)) - which is better and what exactly is O(log(n))?

萝らか妹 提交于 2019-11-29 20:25:39
This is my first course in data structures and every lecture / TA lecture , we talk about O(log(n)) . This is probably a dumb question but I'd appreciate if someone can explain to me exactly what does it mean !? It means that the thing in question (usually running time) scales in a manner that is consistent with the logarithm of its input size. Big-O notation doesn't mean an exact equation, but rather a bound . For instance, the output of the following functions is all O(n): f(x) = 3x g(x) = 0.5x m(x) = x + 5 Because as you increase x, their outputs all increase linearly - if there's a 6:1

Labelling logarithmic scale display in R

☆樱花仙子☆ 提交于 2019-11-29 17:25:13
问题 While plotting histogarm, scatterplots and other plots with axes scaled to logarithmic scale in R, how is it possible to use labels such as 10^-1 10^0 10^1 10^2 10^3 and so on instead of the axes showing just -1, 0, 1, 2, 3 etc. What parameters should be added to the commands such as hist(), plot() etc? 回答1: Apart from the solution of ggplot2 (see gsk3's comment), I would like to add that this happens automatically in plot() as well when using the correct arguments, eg : x <- 1:10 y <- exp(1