logarithm

Exponentiate very large numbers in R

南楼画角 提交于 2019-12-11 06:33:53
问题 I have the logarithms of very large values, for example: log_a = 1347 log_b = 1351 And I am trying to solve this expression: exp(log_a) - (0.1 * exp(log_b)) Or equivalently this (same expression just in a different form): exp( log_a ) - exp( log(0.1) + log_b ) But of course every time I try to compute exp(log_a) or exp(log_b) values I get Inf. Are there any tricks I can use to get a real result for exp(log_a) - (0.1 * exp(log_b)), either in logarithm or exponential form? Thank you very much

Matrix Logarithm in Base 2

*爱你&永不变心* 提交于 2019-12-11 05:38:15
问题 Logm() takes the matrix logarithm, and log2() takes the logarithm base 2 of each element of a matrix. I'm trying to compute the Von Neumann entropy, which involves the base 2 matrix logarithm. How do I do this? 回答1: If you define the matrix exponential "with base 2" as B = expm(log(2) .* A) , or if you analogously directly define the matrix logarithm "with base 2" via an eigendecomposition with the standard logarithm of base 2 applied eigenvalue-wise, then you can obtain a corresponding base

MatLab: Weird display of logarithmic z-axis and bar3

折月煮酒 提交于 2019-12-11 03:14:55
问题 I want to display a 3d histogram using bar3 plot. Using linear scales with respect to x-, y-, and z-axis gives the following result: However, since the z-values have a very large interval I want to use a logarithmic z-axis such that the lower z-values are also visible. However, setting the z-axis to logarithmic with set(gca, 'ZScale', 'log'); yields the following plot, which does not look good: Is there some extra option I need to set or is it a known bug? Thanks in advance! 回答1: This is a

Java: Generating a random numbers with a logarithmic distribution

╄→尐↘猪︶ㄣ 提交于 2019-12-10 19:05:00
问题 I am attempting to generate a random numbers with a logarithmic distribution. Where n=1 occurs half of the time, n=2 occurs a quarter of the time, n=3 occurs an eighth of the time, etc. int maxN = 5; int t = 1 << (maxN); // 2^maxN int n = maxN - ((int) (Math.log((Math.random() * t)) / Math.log(2))); // maxN - log2(1..maxN) System.out.println("n=" + n); Most of the time, I am getting the result I need, however once every so often, I get a value of n that is larger than maxN . Why is this so?

highcharts: Other settings for y-axis. Dealing with large numbers

喜你入骨 提交于 2019-12-10 16:25:57
问题 I am having some difficulty trying to manage/plot out large numbers in the y-axis in combination with small numbers. Example's are here for both y-axis types: http://jsfiddle.net/index/6FBec/1/ For the first graph (linear): The problem's are that the small numbers gets plotted almost flat on the bottom. For the second graph (logarithmic): Where as here (this is actually better), when the large number gets too large, the gap for the next tick is way far (graph2 last point 12,250 and largest y

problem with arithmetic using logarthms to avoid numerical underflow

﹥>﹥吖頭↗ 提交于 2019-12-10 15:46:23
问题 I have two lists of fractions; say A = [ 1/212, 5/212, 3/212, ... ] and B = [ 4/143, 7/143, 2/143, ... ] . If we define A' = a[0] * a[1] * a[2] * ... and B' = b[0] * b[1] * b[2] * ... I want to calculate the values of A' / B' , My trouble is A are B are both quite long and each value is small so calculating the product causes numerical underflow very quickly... I understand turning the product into a sum through logarithms can help me determine which of A' or B' is greater ie max( log(a[0])

Plotting Log scale in R

泄露秘密 提交于 2019-12-10 11:55:58
问题 I'm trying to plot a logarithmic scale, but I keep on getting this error: Error in plot.window(...) : invalid "log=1/h" specification. I'm not sure what I am doing wrong. Below is my code: #function function(stepsize, temp_val, counter) { while(counter < 0) { counter <- counter + stepsize px_norm <- dnorm(counter, mean = 0, sd = .04) temp_val <- temp_val + px_norm } temp_val <- 2*temp_val temp_val <- temp_val *(stepsize/2) print(temp_val, digits = 12) } #Initial step size h <- .01 while (h >

Trying to Calculate logarithm base 10 without Math.h (Really close) Just having problems with connecting functions [closed]

梦想与她 提交于 2019-12-10 11:25:56
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . I'm trying to learn how to calculate the logarithm base 10 of any numbers that I enter via scanf to my code. I figure that I could calculate the ln(a) a being the number input. I have a working code that calculates this; however now i just want to divide any numbers that my ln(a) code outputs by

Minimum number of bits are to represent a given `int`?

守給你的承諾、 提交于 2019-12-10 10:38:28
问题 In C++, what's the fastest way to find out how many bits are needed to store a given int? I can try dividing the number with 2 many times but divisions are pretty slow. Is there any fast way? edit: Thanks a lot for the answers guys. When I say an int my post, I mean any 4 byte int. For example, if I store 30665, I want to get as a result 15 bits. 回答1: You can break the value progressively by halves to narrow it down faster. int bits_needed(uint32_t value) { int bits = 0; if (value >= 0x10000)

How to evaluate logarithms in Maxima?

こ雲淡風輕ζ 提交于 2019-12-10 10:25:11
问题 Following examples from here, and here I tried this: log2(x) := log(x) / log(2); log2(8), float; But this doesn't give 3, instead I get log(8)/log(2) . 回答1: You have to simplify radicals: (%i1) log2(x) := log(x) / log(2); log(x) (%o1) log2(x) := ------ log(2) (%i2) radcan(log2(8)); (%o2) 3 回答2: or use float : float(log(8)/log(2)); gives: 2.999999999999999 来源: https://stackoverflow.com/questions/36271504/how-to-evaluate-logarithms-in-maxima