Hi everyone after trying for a week to come up with the math formula. I found mynote I made a long time ago on linear equations.

Below are the results from my notes and a salution I came up with for taking any size input and converting it on a linear scale to make the scaled value fall between a min and max value.

equations used in calculating a linear relationship:

Scaled value = (input value x rate) + offset

Rate = (scaled max. - scaled min.) / (input max. - input min.)

Offset = scaled minimum - (input minimum x rate)

Translation to needed formula

Original new description

Scaled value = r =(rate of deduction)

scaled max. = rmax =(r maximum scale)

scaled min. = rmim =(r minimum scale)

Input Max = Imax =( Maximum value of al)

Input Min = Imin =( minimum value of al)

Rate = Rate1 =(calculated Value)

offset = offset =(calculated value)

err = ( al X rate1 ) + offset

rate1 = ( rmax - rmin ) / ( Imax - Imin )

offset = rmin - ( Imin X rate )

err = (al * (rmax - rmin) / (Imax - Imin)) + (rmin - (Imin * ((rmax - rmin) / (Imax - Imin))))

This formula is a reverse slope. Below is an example.

rmax = .5

rmin = .3

Imax = 1000

Imin = 1

en = 1000

al = 2 to 1000

If the parameters are set as above then running the above formula will result in the following input(al) to output(rate1)

al = 1000 then Rate1 = .300

al = 500 then Rate1 = .400

al = 1 then Rate1 = .500

This is using math.round (rate1,3) as you can see the input to output is reversed a larger number produces a smaller output.

It is also linear from input to output. One thing is you can input numbers larger or smaller than the max,min settings and unpredictable results will result.

Hope this helps anyone having a simular problem.

Curtis

Always Lost in Code,