Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have min and max value of the scale and i want it to divide the scale in N partitions.

Let i have Min = 0 and Max = 200.

That i have tried to get the interval for getting equal distance between two points as:

void Main()
    double s = 012345678;
    double e = 123456789;
    double fx = (e - s)/10;
    double index = s;
    while(index <= e)
    index += fx;

which does some trick and somewhat divided it as i want, but not the solid solution. Sometimes the Min and Max values are too much high as:

Max: 564094825.8374691 Min: 544792373.69823289
Interval = (Max/ Min)/20;

Now it causing problem.

The Result distribution of scale result should be as:

Let xMin= 0 and xMax = 10, I want this scale to divide in 5 intervals
Then it should return 

Min and Max value could be negative as possible while drawing a graph for -5 to 5 x scale or -10 to -5.

I went through this- Take set of values and change scale , is it somewhat relevant to my problem???

Please suggest me the way to achieve this..

thanks in Advance.

share|cite|improve this question
up vote 1 down vote accepted

If your Min is $m$ and your Max is $M$ and you want to divide the range between them into $N$ equal pieces, then let $h=(M-m)/N$ and let your division points be $$m,m+h,m+2h,m+3h,\dots,m+(Nh)=M$$

share|cite|improve this answer
+1 thanks for your answer, i will check and update you whether it solved my problem or not.. thanks again.. – Niranjan Kala Jun 19 '12 at 5:21
well it is same as i am doing, but little difference. thanks it works. – Niranjan Kala Jun 19 '12 at 5:48

Suppose that the minimum possible value is $a$, and the maximum possible value is $b$. We want to map the interval $[a,b]$ to the interval $[0,200]$.

There are a great many possibilities. One of the simplest is a linear mapping, where $x$ is mapped to $f(x)$, with $f(x)=px+q$.

We want $f(a)=0$, so $pa+q=0$. We want $f(b)=200$, so $pb+q=200$.

Now solve the system of equations $pa+q=0$, $\,pb+q=200$ for $p$ and $q$. We get $$p=\frac{200}{b-a},\qquad q=-\frac{200a}{b-a},$$ and therefore $$f(x)=\frac{200}{b-a}\left(x-a\right).$$ You may want to modify this so that the scaled values are integers. If so, then a sensible modification is to use, instead of $f(x)$, the function $g(x)$, where $g(x)$ is the nearest integer to $f(x)$.

Added: If you want to have only $N$ values, equally spaced with bottom at $0$ and top at $200$, then $N-1$ should divide $200$. Let $D=\frac{200}{N-1}$. Take the integer nearest to $\frac{f(x)}{D}$, and multiply the result by $D$. For example, if you want $26$ different values $0, 8, 16, 24, \dots, 200$, then $N=26$, so $N-1=25$ and $D=8$. We find the nearest integer to $\frac{f(x)}{8}$ and multiply the result by $8$.

Remark: One important real world example is when you want to convert the temperature $x$, in degrees Fahrenheit, to temperature in degrees Celsius. In the Fahrenheit scale, the freezing point of water is $32$ degrees, and the boiling point is $212$. In degrees Celsius it is $0$ and $100$. So we want to transform the interval $[32,212]$ to the interval $[0,100]$. the relevant $f(x)$ is equal to $\frac{100}{212-32}(x-32)$, which simplifies to $f(x)=\frac{5}{9}(x-32)$.

share|cite|improve this answer
Thanks @Andre for your nice explanation. please review the updated question modification and suggest me about that.. i want equal intervals between min and max values. i know only min and max value, not mapping some external scale. i am not doing exact that done in link specified in my question. – Niranjan Kala Jun 19 '12 at 5:03
Min and max look like all you need. If you only want $N$ equally spaced values, like $N=11$ (we want $N-1$ to divide $200$, the final rounding should be a little different from the one I described. I will add something about that to the post. – André Nicolas Jun 19 '12 at 5:16
+1:thanks @Andre for reply. i will check and wait for your edits.. – Niranjan Kala Jun 19 '12 at 5:23
@NiranjanKala: The first time I wrote out the modification, I made a mistake. It is now right. – André Nicolas Jun 19 '12 at 5:29
well, it's alright i will try to check @Gerry answer and your will also help others.. have a nice time.. – Niranjan Kala Jun 19 '12 at 5:35

Your Answer


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.