19
$\begingroup$

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. ?

$\endgroup$
1
  • $\begingroup$ For example $x ↦ 100(x + 1)$? Or do you mean something else? $\endgroup$
    – k.stm
    Apr 30 '13 at 12:24
35
$\begingroup$

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=(x-a)\frac{d-c}{b-a}+c$$

$\endgroup$
14
  • 1
    $\begingroup$ Thanks. What is the name/tag of such a formula? $\endgroup$
    – some_id
    Apr 30 '13 at 13:17
  • 1
    $\begingroup$ I'd say it's an affine transformation. $\endgroup$
    – Matt L.
    Apr 30 '13 at 15:33
  • $\begingroup$ 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. $\endgroup$ Nov 6 '13 at 4:31
  • $\begingroup$ That's slope intercept form of line equation and that's brilliant indeed. $\endgroup$ Jul 23 '17 at 13:03
  • 1
    $\begingroup$ @Talespin_Kit: By definition, $y=ax+b$ is an affine transformation. $\endgroup$
    – Matt L.
    Dec 13 '19 at 17:05
8
$\begingroup$

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)$.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.