1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Logarithmic Scale

  1. Apr 3, 2009 #1
    Hello All,

    I am working on a program that produces plots that use a logarithmic scale on the X-Axis (for showing decade frequency ranges). The Y-axis can have any arbitrary value and I'm not thinking about that at this point, but here is my question.

    Say, for simplicity that every Y-value on the graph was set to a value of 10 so that a straight line is always drawn. Is there a way to determine the X coordinates such that they appear to be evenly spaced going from left to right on the graph even though the X-axis is displaying a logarithmic scale? I want to know this so that I can generate a plot that has x number of evenly spaced points. The second challenge is I want to be able to specify a starting and ending point on the X-axis to draw the graph (it may not always start at 0). How would I design a formula that if I enter the starting X value, end X-value, and number of points, that i could spit out point n in the range to plot a function with?

    Thanks,
    Jason O
     
  2. jcsd
  3. Apr 3, 2009 #2
    I think so.

    Say you're doing the logarithms to the base of 10. Then to get evenly spaced x-coordinates when the x-axis is on a log scale, just start with a number (1, for instance) and multiply by 10 over and over again. So

    x = 1, 10, 100, ..., 10^n

    Taking the Log gives you:

    Log x = 0, 1, 2, ..., n

    Which, I believe, is exactly what you wanted.


    Say you wanted them spaced at intervals of 2 rather than 1. Then multiply by 100 each time. Say you wanted 1/2. Then try sqrt(10). Etc.
     
  4. Apr 3, 2009 #3
    So Far here is what I have come up with so far, only this function works for a linear scale and not logarithmic:

    x(n) = (n(End - Start) / Count) + Start

    where:

    n = position in the array of points
    End = Ending X coordinate
    Start = Starting X coordinate
    Count = Number of points in the array

    I basically want to figure out how to convert this function to the other scale.

    - Jason O
     
  5. Apr 3, 2009 #4
    Hi AUMathTutor,

    That sounds like the right idea. But I'm not sure how to implement it when you have arbitrary starting and ending points along with n number of points specified.

    Thanks,
    Jason O
     
  6. Apr 3, 2009 #5
    Alright, so you want "count" many evenly-spaced points between "start" and "end".

    First, get the log base 10 of start. Call it log_start. Then get the log base 10 of end. Call it log_end.

    Next, generate evenly spaced points using the same method you posted above, but call the array log_x(n). So we have...

    log_x(n) = (n(log_end - log_start) / Count) + log_start

    Then, just go through the array and set

    x(n) = pow(10, log_x(n))
     
  7. Apr 3, 2009 #6
    For instance, let start=10, end=10,000, and count=4. Then...

    log_start = 1
    log_end = 4

    log_x(0) = log_start
    log_x(1) = (log_end - log_start)(1/4) + log_start = (1/4)log_end + (3/4)log_start
    log_x(2) = (log_end - log_start)(2/4) + log_start = (1/2)log_end + (1/2)log_start
    log_x(3) = (log_end - log_start)(3/4) + log_start = (3/4)log_end + (1/4)log_start
    log_x(4) = (log_end - log_start) + log_start = log_end

    so...

    x(0) = start = 10
    x(1) = (end)^(1/4) + (start)^(3/4) = 15.623413251903490803949510397765
    x(2) = (end)^(1/2) + (start)^(1/2) = 103.16227766016837933199889354443
    x(3) = (end)^(3/4) + (start)^(1/4) = 1,001.7782794100389228012254211952
    x(4) = end = 10,000

    There you have it. You'll have to iron out issues related to whether you want count or count+1 points, but still. The idea is there.
     
  8. Apr 3, 2009 #7
    Thank you very much! I'll try this out and let you know what I end up with :smile:.
     
  9. Apr 7, 2009 #8
    Hi AUMathTutor,

    I finally had a chance to test out the formula you gave me. It works like a charm! Thanks!

    - Jason O
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Logarithmic Scale
  1. Logarithmic Scale (Replies: 4)

  2. Logarithms problem (Replies: 2)

Loading...