Logarithmic Scale: Calculating Evenly Spaced X Values

In summary, Jason O is working on a program that produces plots with a logarithmic scale on the x-axis and arbitrary values on the y-axis. They are wondering if there is a way to determine evenly spaced x-coordinates on a logarithmic scale, and if there is a formula that can be used with specified starting and ending points on the x-axis. AUMathTutor suggests using the logarithm function to generate evenly spaced points and then converting them to the desired scale. Jason O thanks AUMathTutor for the helpful solution.
  • #1
Jdo300
554
5
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
 
Mathematics news on Phys.org
  • #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.
 
  • #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
 
  • #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
 
  • #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))
 
  • #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.
 
  • #7
Thank you very much! I'll try this out and let you know what I end up with :smile:.
 
  • #8
Hi AUMathTutor,

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

- Jason O
 

What is a logarithmic scale?

A logarithmic scale is a scale used in graphs and charts where the values increase exponentially. This means that each increment on the scale represents a multiplication of the previous value by a constant factor.

Why is a logarithmic scale used?

A logarithmic scale is used to better represent data that covers a wide range of values. It allows for easier comparison of data points and can make it easier to identify trends or patterns in the data.

How do you calculate evenly spaced X values on a logarithmic scale?

To calculate evenly spaced X values on a logarithmic scale, you can use the formula x = a * b^n, where a is the starting value, b is the constant factor, and n is the number of increments on the scale. This will give you evenly spaced values that increase exponentially.

What is the constant factor in a logarithmic scale?

The constant factor in a logarithmic scale is the number by which the previous value is multiplied to get the next value on the scale. It is typically a number greater than 1, and it determines the rate of increase on the scale.

Can a logarithmic scale be used for negative values?

Yes, a logarithmic scale can be used for both positive and negative values. However, the values must be evenly spaced and the base of the logarithm must be a positive number. This is known as a logarithmic scale with a non-positive base.

Similar threads

  • General Math
Replies
2
Views
9K
  • General Math
Replies
7
Views
1K
Replies
1
Views
1K
Replies
4
Views
2K
  • General Math
Replies
7
Views
964
  • Other Physics Topics
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
Replies
4
Views
3K
Replies
76
Views
4K
Replies
16
Views
1K
Back
Top