How does one calculate the value within range $1.0$ to $1.0$ to be a number within the range of e.g. $0$ to $200$, or $0$ to $100$ etc. ?
Asked
Active
Viewed 2.1k times
19

For example $x ↦ 100(x + 1)$? Or do you mean something else? – k.stm Apr 30 '13 at 12:24
2 Answers
35
If you have numbers $x$ in the range $[a,b]$ and you want to transform them to numbers $y$ in the range $[c,d]$ you need to do this:
$$y=(xa)\frac{dc}{ba}+c$$
Matt L.
 10,199
 15
 25

1

1

This is brilliant!! I'm surprised I've never seen something like this before. I knew what I was trying to do was simple, yet I couldn't do it mentally. – Michael Lewis Nov 06 '13 at 04:31

That's slope intercept form of line equation and that's brilliant indeed. – Ankit singh kushwah Jul 23 '17 at 13:03



I guess this doesn't work if the scale (distribution?) changes. I have a number ranging from [0, 1] which should map to [1, 1], but 0.25 would map to 0. – Ray Jun 12 '18 at 18:30

@RayKoopa: In your example, $0.25$ maps to $0.5$, as it should. You just have to do the math right ... – Matt L. Jun 12 '18 at 18:51

@MattL. I'm afraid those weird mappings were given to me and I had to somehow transform between them with the above samples. It turned out the first range is now only between [0, 0.5], and now it makes sense as y = (x  0.25) * 4. – Ray Jun 12 '18 at 19:12

@MattL. How is this affine transformation ? It does not fit as "tranform" , "scale" , "shear" or "rotation" . – Talespin_Kit Dec 13 '19 at 16:40

1@Talespin_Kit: By definition, $y=ax+b$ is an [affine transformation](https://en.wikipedia.org/wiki/Affine_transformation). – Matt L. Dec 13 '19 at 17:05

@MattL.Could you please be more specific. I am unable to see how line equation has anything to do with it. – Talespin_Kit Dec 13 '19 at 18:18


9
A short proof of Matt L.'s answer:
We want a function $f: [a, b] \rightarrow [c, d]$ such that
$$ \begin{alignat}{2} f&(&a) &= c \\ f&(&b) &= d. \end{alignat} $$
If we assume the function is to be linear (that is, the output scales as the input does), then
$$\dfrac{d  c}{b  a} = \dfrac{f(x)  f(a)}{x  a}.$$ Simplifying yields the desired formula for $y = f(x)$.
t.y
 455
 5
 14

An alternative way to see this: $t = (xa)/(ba)$ maps from $[a, b]$ to $[0, 1]$. Then $t (dc) + c$ maps $t$ from $[0, 1]$ to $[c, d]$. – Fizz Jan 05 '22 at 21:51