13

Given a number n, how would I convert this number into a logarithmic scale?

My logarithmic scale would range from 0 to 255 (I'm working with RGB colours), and I would expect values of n from 1 to 1,000,000.

Apologies if this is an easy question.

1 Answers1

14

let $f(n)$ be the log function of n.

So a general log function can be written as $f(n)=k\log n +c$

where $k$ and $c$ are constants

$\implies 255=k\log {10^6}+c$

and $0=k\log {1}+c$

here is to the base 10

so $c=0$ and $k=255/6$

or here you can use any base and different values of k

so that $f(n)=\frac {255 \log n}{6}$ if the base is 10.

Jasser
  • 1,976
  • 2
    Thanks, that's great. How would I approach the problem if I expected values of n that ranged from 0 to 1,000,000 (since log 0 is undefined)? – James Williams Oct 12 '14 at 15:33
  • 1
    Then you can redifine your function as $f(n)=klog(p+n) + c (p=10^6) $ Here you can get values of k and c by substituting 0 and 255 in the place of $f(n)$ and $n=0, 10^6$ respectively. Don't forget to upvote and if satisfied mark as correct answer. – Jasser Oct 13 '14 at 06:36
  • 1
    What is p? And how can a function have p = 10^6 in it? – Ian Warburton May 11 '15 at 15:52
  • @Jasser Just like to follow up on Ian Warburton's comment. Is p simply equal to your maximum value? – Boumbles Sep 11 '15 at 13:15
  • 1
    p is just a number so that the value of log is defined even for n=0 case. U can take it as any number such that your function is always defined. Moreover if u do this there is nothing wrong going on because the function would still be logarithmic. @Boumbles – Jasser Sep 11 '15 at 15:58
  • 1
    @IanWarburton sorry to respond so so late.... thanks to Boumbies' I saw your comment. Are the ranges of logx and log(x+c) equal where c is any real constant. If yes, then taking p=10^6 should not mind u because the function would still be logarithmic. – Jasser Sep 11 '15 at 16:05