Logarithm of a BigDecimal

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 following has been taken from chapter 12.5 Big Decimal Functions (p330 & p331): /** * Compute the natural logarithm of x to a given scale, x > 0. */ public … Read more

Convert Linear scale to Logarithmic

Notation As is the convention both in mathematics and programming, the “log” function is taken to be base-e. The “exp” function is the exponential function. Remember that these functions are inverses we take the functions as: exp : ℝ → ℝ+, and log : ℝ+ → ℝ. Solution You’re just solving a simple equation here: … Read more

Logarithmic y-axis bins in python

try plt.yscale(‘log’, nonposy=’clip’) http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.yscale The issue is with the bottom of bars being at y=0 and the default is to mask out in-valid points (log(0) -> undefined) when doing the log transformation (there was discussion of changing this, but I don’t remember which way it went) so when it tries to draw the rectangles for … Read more

python: scatter plot logarithmic scale

let matplotlib take the log for you: fig = plt.figure() ax = plt.gca() ax.scatter(data[‘o_value’] ,data[‘time_diff_day’] , c=”blue”, alpha=0.05, edgecolors=”none”) ax.set_yscale(‘log’) ax.set_xscale(‘log’) If you are using all the same size and color markers, it is faster to use plot fig = plt.figure() ax = plt.gca() ax.plot(data[‘o_value’] ,data[‘time_diff_day’], ‘o’, c=”blue”, alpha=0.05, markeredgecolor=”none”) ax.set_yscale(‘log’) ax.set_xscale(‘log’)

Histogram with Logarithmic Scale and custom breaks

A histogram is a poor-man’s density estimate. Note that in your call to hist() using default arguments, you get frequencies not probabilities — add ,prob=TRUE to the call if you want probabilities. As for the log axis problem, don’t use ‘x’ if you do not want the x-axis transformed: plot(mydata_hist$count, log=”y”, type=”h”, lwd=10, lend=2) gets … Read more

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

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 … Read more

set ticks with logarithmic scale

import matplotlib from matplotlib import pyplot as plt fig1, ax1 = plt.subplots() ax1.plot([10, 100, 1000], [1,2,3]) ax1.set_xscale(‘log’) ax1.set_xticks([20, 200, 500]) ax1.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter()) or ax1.get_xaxis().get_major_formatter().labelOnlyBase = False plt.show()

Logarithmic slider

You can use a function like this: function logslider(position) { // position will be between 0 and 100 var minp = 0; var maxp = 100; // The result should be between 100 an 10000000 var minv = Math.log(100); var maxv = Math.log(10000000); // calculate adjustment factor var scale = (maxv-minv) / (maxp-minp); return Math.exp(minv … Read more