Link to home
Start Free TrialLog in
Avatar of skij
skijFlag for Canada

asked on

Adjust number proportionately

x may be any positive number.

y may be any positive number.

f should be the the value of x, adjusted proportionately so that:

   •  if the value of y is 1, the value of f should be 1
   •  if the value of y is 50, the value of f should be x
   •  if the value of y  is 100, the value of f should be 1
   •  if the value of y  is less than 1, the value of f should be less than 1
   •  if the value of y  is more than 100, the value of f should be less than 1

Eventually, I will incorporate this into a PHP script.

Using math, math functions, absolute values and algebra are acceptable.

However, I would like the solution to be as simple as possible.
SOLUTION
Avatar of Olaf Doschke
Olaf Doschke
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skij

ASKER

The proportionately is not what I want.  I do not want this to be linear.  I want it to me more like a bell curve, with the peak when y is 50.

If x is 0 then f should be 0 regardless of the value of y.
y will never be 0.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is f always positive?
Proportional is subjective. You said you didn't want linear proportionality... so did you want hyperbolic, harmonic, exponential, or some other type of proportionality?
Avatar of skij

ASKER

f is based on y so that if y is positive, f should also be positive.  Because y is always positive, f is also always positive.   Exponential proportionality would be preferred.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skij

ASKER

We could use between 1 and 101 instead of 1 and 100 if it would peak more symmetrically.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And just in case you have only data and need to know how to calculate everything, including debug:

<?php
$x = 10;					// test value (input)
echo 'x = ' . $x . '<br>';
$data = array(1,4,9,16,25); // test data (input)
$ave = array_sum($data) / count($data);	// MEAN (average)
echo 'm = ' . $ave . '<br>';
$ss = 0;
echo 'data[';
$d= '';
foreach ($data as $key => $value){
 $ss = $ss + pow(($value - $ave), 2); // add each deviation squared to running total
 $d .= $value . ',';
 }
$d = rtrim($d, ',');
echo $d . ']<br>';
echo 'ss = ' . $ss . '<br>';		// SUM OF SQUAREs deviations
$v = $ss / count($data);	// VARIANCE (population)
echo 'v = ' . $v . '<br>';
$stdev = sqrt($v);			// STANDARD DEVIATION (population)
echo 'stdev = ' . $stdev . '<br>';
$z = ($x - $ave)/$stdev;	// Z-SCORE of X
echo 'z = ' . $z . '<br>';
$y = exp(-pow($z, 2));		// Gauss proportionality to mean.
echo 'y = ' . $y . '<br>';
?>

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial