Skip to content

Rescale ​

Linearly rescale a value or list from one range to another.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageRescale!
Rescale(list)rescale every element of list so its own minimum maps to 0 and its maximum to 1.
Rescale(x, {min, max})(x - min) / (max - min) -- x rescaled from {min, max} to {0, 1}.
Rescale(x, {min, max}, {ymin, ymax})x rescaled from {min, max} to {ymin, ymax}.
Typed signatures
TypePackageApplies
(list<real> | real, vector<real^2>?, vector<real^2>?) -> list<real> | realanalyticalways

Domain: Elementary functions

Details
  • A bare scalar with no range to rescale against -- Rescale(x) where x is not a list -- has no sensible reading and stays unevaluated.
  • Rescale(x, {min, max}) is Rescale(x, {min, max}, {0, 1}) with the target range left implicit.
  • Exact rational input and bounds give an exact rational result, which N(…, d) rounds once, so every digit asked for is right.

Examples

Basic #

List min -> 0, max -> 1

live ↗
InRescale([1,2,3,4])\mathrm{Rescale}(\bigl\lbrack1, 2, 3, 4\bigr\rbrack)Out[0,13,23,1]\bigl\lbrack0, \frac{1}{3}, \frac{2}{3}, 1\bigr\rbrack
Scope #
live ↗
InRescale(5,[0,10])\mathrm{Rescale}(5, \bigl\lbrack0, 10\bigr\rbrack)Out12\frac{1}{2}

Rescaled into an explicit target range

live ↗
InRescale(5,[0,10],[100,200])\mathrm{Rescale}(5, \bigl\lbrack0, 10\bigr\rbrack, \bigl\lbrack100, 200\bigr\rbrack)Out150150

Maps −32-\frac32 in [−2,2][-2,2] to the fraction 18\frac18 of the way across

live ↗
InRescale(−32,[−2,2])\mathrm{Rescale}(-\frac{3}{2}, \bigl\lbrack-2, 2\bigr\rbrack)Out18\frac{1}{8}

Maps 3 from [−9,7][-9,7] into [11,28][11,28] linearly

live ↗
InRescale(3,[−9,7],[11,28])\mathrm{Rescale}(3, \bigl\lbrack-9, 7\bigr\rbrack, \bigl\lbrack11, 28\bigr\rbrack)Out954\frac{95}{4}

A list rescales to the unit interval

live ↗
InRescale([−2,0,2])\mathrm{Rescale}(\bigl\lbrack-2, 0, 2\bigr\rbrack)Out[0,12,1]\bigl\lbrack0, \frac{1}{2}, 1\bigr\rbrack

The derivative stays unevaluated when the limits are symbols

live ↗
InPiecewiseExpand(D⁡(Rescale(x,[a,b]),[x,k]))\mathrm{PiecewiseExpand}(\operatorname{D}(\mathrm{Rescale}(x, \bigl\lbrack a, b\bigr\rbrack), \bigl\lbrack x, k\bigr\rbrack))OutD⁡(Rescale(x,[a,b]),[x,k])\operatorname{D}(\mathrm{Rescale}(x, \bigl\lbrack a, b\bigr\rbrack), \bigl\lbrack x, k\bigr\rbrack)
live ↗
InN(Rescale(111,[17,5]),50)N(\mathrm{Rescale}(\frac{1}{11}, \bigl\lbrack\frac{1}{7}, 5\bigr\rbrack), 50)Out−0.010 695 187 165 775 401 069 518 716 577 540 106 951 871 657 754 011-0.010\,695\,187\,165\,775\,401\,069\,518\,716\,577\,540\,106\,951\,871\,657\,754\,011
About
Examples8
Checked againstWolfram Language 7 agree1 differ
CrosswalkWolfram Language