Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'd like to get exactly 5 divisions from x to y on a log scale. Can FindDivisions do this?

share|improve this question

2 Answers

Writing one wouldn't be that hard. You can convert it to Log10 and then let FindDivisions do all the work in log space before converting it back. For example:

findLogDivisions[{xmin_, xmax_}, n_Integer] := 10^FindDivisions[Log10@{xmin, xmax}, n]

Then, to find 4 "nice" divisions in log space between 1 and 1000, you simply need to do:

findLogDivisions[{1, 1000}, 5] 
(* {1, 10, 100, 1000} *)
share|improve this answer

I built a function that calculates log spaced increments for a job at work. I've added a catch where it will handle log spacing from 0 to a number.

logspace [increments_, start_, end_] := Module[{a}, (
   a = Range[0, increments];
   Exp[a/increments*Log[(end - start) + 1]] - 1 + start
   )]

To try it out:

N@logspace[5,1,1000]

(*{1., 3.98107, 15.8489, 63.0957, 251.189, 1000.}*)

To view it on a number line:

a = N@logspace[10, 0, 10];
Graphics[Point@Transpose[{a, ConstantArray[.5, 11]}], Axes -> {True, False}, 
   AxesStyle -> Arrowheads[.05]]

enter image description here

And if you want to find the distances between divisions, use Differences:

Differences[a]

(*{0.270982, 0.344413, 0.437742, 0.556362, 0.707126, 0.898744, 1.14229, 1.45183, 1.84524, 2.34527}*)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.