How to Map a Range to -1 to 1 in Relationships?

  • Context: MHB 
  • Thread starter Thread starter SLSCoder
  • Start date Start date
  • Tags Tags
    Relationships
Click For Summary

Discussion Overview

The discussion revolves around mapping a numerical range defined by two values, referred to as "high" and "low," to a new range between -1 and 1. Participants explore the mathematical transformation needed to achieve this mapping, including the representation of an intermediate variable within the specified bounds.

Discussion Character

  • Mathematical reasoning

Main Points Raised

  • One participant describes the need to map a range defined by "high" and "low" to the interval of -1 to 1, specifying that the high value is greater than the low value.
  • Another participant provides a mathematical formula for the transformation, assuming the variable lies within the bounds of low and high.
  • A third participant seeks clarification on the formula and confirms the correct representation of the variables in the equation.
  • A later reply affirms the correctness of the variable names used in the formula.

Areas of Agreement / Disagreement

Participants appear to agree on the mathematical approach to mapping the range, but there is no explicit consensus on the final implementation details or any potential edge cases.

Contextual Notes

Assumptions include that the variable lies strictly between the low and high values, and the discussion does not address potential issues with edge cases or the implications of using fractional values.

SLSCoder
Messages
4
Reaction score
0
I have a number, the high, that could be positive, negative or zero and can be a fraction.
I have another number, the low, that could also be positive, negative or zero and can be a fraction.
I have another number, the variable that is between the high and the low.

It is safe to say that the high is greater than the low.
I need to represent the high as 1 and the low as -1.
Then I need to determine what the variable value would be (between 1 and -1).

How can I solve this?
 
Physics news on Phys.org
$$\text{So you are mapping the interval $[low,~high]$ to the interval $[-1,1]$}\\
\text{Let $x$ be your variable that you want to transform, and $\tilde{x}$ be it's new value}\\
\text{It's assumed that $low \leq x \leq high$}\\~\\
\tilde{x} = -1 + 2\dfrac{x-low}{high - low},~ -1 \leq \tilde{x} \leq 1$$
 
Thank you!
I need to write this function in code (software).
My math is pretty bad so I just want to clarify that the equation looks like this?

This is correct: low ≤ x ≤ high

-1 + 2 * ((X - lo) / (hi - lo));

I sure appreciate your help.
 
looks good if your variables are now called hi and lo
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
Replies
1
Views
1K
Replies
13
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K