Linear to logarithmic scale conversion

In summary, the conversation discusses implementing a logarithmic scale in a computer program for graphing purposes, with the desired range being from 0 to 1. The solution suggested is using the log function in C++ to transform the values into the desired range.
  • #1
jocasa
4
0
Hi!

I'm making a computer program that represents some quantities in a graph in this way:

x'i=(xi-xmin)/(xmax-xmin)

so that the possible values of x range from 0 to 1. This is a linear scale. I want to do the same with the logarithmic values of xi. That is, I want to implement a log scale in my graphs, also in the range from 0 to 1.

Can anyone tell me how to do it?

Thanks!
 
Mathematics news on Phys.org
  • #2
jocasa said:
Hi!

I'm making a computer program that represents some quantities in a graph in this way:

x'i=(xi-xmin)/(xmax-xmin)

so that the possible values of x range from 0 to 1. This is a linear scale. I want to do the same with the logarithmic values of xi. That is, I want to implement a log scale in my graphs, also in the range from 0 to 1.

Can anyone tell me how to do it?

Thanks!

Welcome to the PF.

What language are you programming in? Does it have any math libraries that cover logarithms?
 
  • #3
I'm using C++ and it has both log and log10 functions, that is, log in base e and log in base 10.

I'm not sure if I made myself clear in my first post. I want to be able to make log-log plots, transforming the resulting plot into the [0,1] interval.
 
  • #4
jocasa said:
Hi!

I'm making a computer program that represents some quantities in a graph in this way:

x'i=(xi-xmin)/(xmax-xmin)

so that the possible values of x range from 0 to 1. This is a linear scale. I want to do the same with the logarithmic values of xi. That is, I want to implement a log scale in my graphs, also in the range from 0 to 1.

Can anyone tell me how to do it?

Thanks!
I think this will work:

x'i = (log(xi)-log(xmin)) / (log(xmax)-log(xmin))​
As a test, we can see that if xmin,max are 1 and 100, then xi=10 gives x'i=0.5. As it should, since 10 is halfway between 1 and 100 on a log scale.
 
  • #5
Thanks! It makes sense to me. Now the problem is to implement it in the program, but I won't bother you with such a thing. Thanks again from Spain!
 

1. What is the purpose of converting from linear to logarithmic scale?

The purpose of converting from linear to logarithmic scale is to transform a large range of numerical values into a more manageable and visually understandable scale. This is especially useful when dealing with very large or small numbers.

2. How does the conversion from linear to logarithmic scale work?

The conversion from linear to logarithmic scale is based on the mathematical concept of logarithms. Logarithms are used to compress a wide range of numbers into a smaller range, making it easier to compare and analyze data. The formula for converting from linear to logarithmic scale is y = log10(x), where x is the original value and y is the converted value.

3. What is the difference between linear and logarithmic scales?

The main difference between linear and logarithmic scales is the way they display numerical values. Linear scale has equal spacing between each tick mark, while logarithmic scale has an increasing spacing between each tick mark. This means that on a logarithmic scale, the distance between 1 and 10 is the same as the distance between 10 and 100, while on a linear scale, the distance between each number is the same.

4. When should I use a logarithmic scale instead of a linear scale?

A logarithmic scale is useful when dealing with data that has a large range of values, such as in scientific or financial data. It can also be used when there is a need to highlight small changes in data that may not be easily visible on a linear scale.

5. What are the advantages and disadvantages of using a logarithmic scale?

The main advantage of using a logarithmic scale is that it can make data easier to interpret and visualize, especially when dealing with large or small numbers. It can also highlight small changes in data that may not be easily visible on a linear scale. However, a disadvantage of using a logarithmic scale is that it can sometimes be misleading or confusing, as the spacing between values is not even. It can also be more difficult for individuals who are not familiar with logarithms to understand the data.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
8
Views
1K
Replies
17
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
Replies
4
Views
3K
  • General Math
Replies
4
Views
1K
  • General Math
Replies
4
Views
7K
Replies
7
Views
11K
Replies
1
Views
909
Replies
6
Views
2K
Replies
24
Views
2K
Back
Top