2
$\begingroup$

Does Mathematica have a mapping function like scipy or any of the multidimensional ones?

By this I mean something like mapping $[1,100]$ onto $[7,20]$ for example.

Looking at Interpolate I only see interpolation with regards to estimating a line given points.

To make it more clear I mean a simple example using a linear mapping would be $[0,512]$ onto $[0,10]$ would give 5 for a value of 256.

Edited: (Comments added for greater precision):

  1. What would make the question more clear? An example would be reading in a sensor that gives values on $[0,256]$ and using those to operate say a servo which accepts values on $[0,10]$

  2. in this scale that is exactly what I'm looking for! thanks. Is it possible to use mappings of other orders, ex. a normal distribution or a quadratic mapping? This being a linear mapping. –

$\endgroup$
6
  • 1
    $\begingroup$ I don't understand what your asking for. $\endgroup$
    – rcollyer
    Commented Apr 10, 2012 at 1:13
  • 2
    $\begingroup$ Do you mean splines? reference.wolfram.com/mathematica/guide/Splines.html $\endgroup$ Commented Apr 10, 2012 at 1:55
  • $\begingroup$ Are you looking for Rescale[256, {0,512}, {0,10}] (==> 5)? $\endgroup$ Commented Apr 10, 2012 at 2:22
  • $\begingroup$ @BrettChampion in this scale that is exactly what I'm looking for! thanks. Is it possible to use mappings of other orders, ex. a normal distribution or a quadratic mapping? This being a linear mapping. $\endgroup$ Commented Apr 10, 2012 at 2:25
  • 1
    $\begingroup$ The reason why your question was unclear is that you mention interpolation when you need a linear transformation (they're unrelated) and that originally you didn't say at all that you need a linear transformation. There are of course infinitely many (non-linear) mappings from interval $[a,b]$ to interval $[c,d]$. $\endgroup$
    – Szabolcs
    Commented Apr 10, 2012 at 6:57

1 Answer 1

9
$\begingroup$

Your question isn't very clear, but I think you need the Rescale function, especially its 3 argument form:

Rescale[#, {1, 100}, {7, 20}] & /@ Range[1, 100, 5] // N
(* Out[1]= {7., 7.65657, 8.31313, 8.9697, 9.62626, 10.2828, 10.9394, 11.596, 12.2525, 12.9091, 
    13.5657, 14.2222, 14.8788, 15.5354, 16.1919, 16.8485, 17.5051, 18.1616, 18.8182, 19.4747}
 *)
$\endgroup$
3
  • $\begingroup$ what would make the question more clear? An example would be reading in a sensor that gives values on [0,256] and using those to operate say a servo which accepts values on [0,10]. $\endgroup$ Commented Apr 10, 2012 at 2:23
  • $\begingroup$ @EiyrioüvonKauyf Then Rescale is exactly what you want. You should also look into Clip to use along with this if you don't want to give out of bound values to your servo. $\endgroup$
    – rm -rf
    Commented Apr 10, 2012 at 2:59
  • $\begingroup$ @R.M Rescale[] is what I thought about when reading the question, but I agree it wasn't evident. Author, you might want to edit your question adding the precisions you gave in the comments! $\endgroup$
    – CHM
    Commented Apr 10, 2012 at 3:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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