
Elementary Math Fractions, Percentages, Word Problems, Equations, Inequations, Factorization, Expansion 
 LinkBack  Thread Tools  Display Modes 
April 15th, 2015, 12:31 AM  #1 
Newbie Joined: Oct 2014 From: Mars Posts: 27 Thanks: 0  Transform a number?
Hi, can someone please help me to write a formula to transform a number. I'm trying to write a function with 5 parameters: 1) The value to be transformed 2) The values minimum range 3) The values maximum range 4) The destinations minimum range 5) The destinations maximum range For example, lets say I have a value 4 (which belongs in a system that goes from 4 to 10), and I want to transform it into a number (newValue) which ranges from 400 to 1000. At the moment, this is the formula I have: newValue = (value/valuesMaxvaluesMin) * (destinationsMaxdestinationsMin) So if I do: (4/104) * (1000400) = 400 (which is correct) The problem is when I try to use negative numbers, this formula stops working... Example: (5/100) * (1  1) = 1 (which is wrong. Should be 0 since 0 is the middle of 1 and 1, and the values we gave it were 5 in a range of 0 to 10). Thanks in advance, A. 
April 17th, 2015, 01:09 AM  #2 
Senior Member Joined: Apr 2014 From: UK Posts: 780 Thanks: 292 
To work out the destination value, you first need to work out where in the source range your value is. This is achieved by (valuevalueMin)/(valueMaxvalueMin) and gives a value between 0 and 1 Taking the first example of 4, 0 and 10 for value, valueMin and valueMax we get: (44)/(104) = 0, which is correct as it is at the bottom of your range. Next we need to convert this range value to a position in your destination range, which is achieved by: (range * (DesinationMax  DestinationMin) ) + DestinationMin So, again with the first example we get: (0 * (1000  400) ) + 400 = 400, which is correct. Putting both parts together we get: ((valuevalueMin)/(valueMaxvalueMin) * (DesinationMax  DestinationMin) ) + DestinationMin Now if we try the 2nd example with 5, 0, 10, 1 and 1 for the 5 variables, we get: ((5  0)/(10  0) * (1  1)) + 1 = 0, which is correct 
April 17th, 2015, 11:41 PM  #3 
Newbie Joined: Oct 2014 From: Mars Posts: 27 Thanks: 0 
Thanks very much!! 

Tags 
number, transform 
Search tags for this page 
Click on a term to search for related topics.

Thread Tools  
Display Modes  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
natural number multiple of another number if its digit sum equal to that number  Shen  Elementary Math  2  June 5th, 2014 08:50 AM 
Z  transform 1/z1  Frank Lucas  Applied Math  1  May 25th, 2013 10:11 AM 
Transform  ilovetheflowguy  Algebra  9  February 27th, 2012 03:44 PM 
Fourier Transform  progrocklover  Real Analysis  1  March 24th, 2011 09:29 PM 
Fourier Transform  aptx4869  Real Analysis  5  September 3rd, 2008 01:47 AM 