1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

I Convert 2 variables into 1 representative variable

Tags:
  1. Nov 9, 2016 #1
    I need help to convert 2 variables A,B into 1 representative variable C, which is used to filter A,B:

    Below is an example with C=A+B, which makes Set 2 the highest value:
    Set 1: A=65, B=75, C=140;
    Set 2: A=50, B=100, C=150;
    Set 3: A=54, B=90, C=144;
    Set 4: A=72, B=72, C=144;
    Set 5: A=71, B=73, C=144;
    Set 6: A=71, B=71, C=142;

    But I want either Set 4 or 5, which has *both* A and B being closer to 100, and also a high A+B value.

    If you know/understand computer code:
    if(C>previousC) isBestSet=SetNumber;

    I do not care if C is a big or small number, meaning I do not care if I need to pick the biggest or smallest C.
    Thanks
     
  2. jcsd
  3. Nov 9, 2016 #2

    Mark44

    Staff: Mentor

    I'm not sure what adding A and B does for you, but it seems like you want to minimize the distance from a point (A, B) to the point (100, 100)
    For set 4 (the point (72, 72) ), the distance is ##\sqrt{1568}##.
    For set 5 (the point (71, 73) ), the distance is ##\sqrt{1570}##.
    To calculate the distance of a point (A, B) to (100, 100), the formula is ##d = \sqrt{(100 - A)^2 + (100 - B)^2}##.
     
  4. Nov 9, 2016 #3
    Wow. Perfect. Thank you very much.

    I Googled: "minimize the distance from a point"
    I see that this technique is actually the Pythagorean theorem, which leads me to another question:

    Sometimes my Sets have 3 variables instead of 2.
    Is it safe to *assume* that I simply tack on another: + (100-3rdVar)^2
    (i.e. since there is no real need for me to preform the final square root)

    Thanks again.
     
  5. Nov 9, 2016 #4

    Mark44

    Staff: Mentor

    Yes, distance in three dimensions is ##d = \sqrt{(x_1 - y_1)^2 + (x_2 - y_2)^2 + (x_3 - y_3)^2}##. And if ##(x_1, x_2, x_3)## and ##(y_1, y_2, y_3)## are the minimum distance apart, the square of their distance, ##d^2##, will also be at a minimum.
     
  6. Nov 9, 2016 #5

    mfb

    User Avatar
    2017 Award

    Staff: Mentor

    You can also take the largest difference to 100, C=max(100-A, 100-B). There are many functions, the best for you depends on what exactly you want to prefer over what.

    All methods discussed can be extended to 3 variables easily.
     
  7. Nov 9, 2016 #6
    Excellent.
    Thanks again Mark!

    mfb,
    Thanks anyway, but Mark nailed it for me right on the head.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted