Trying to figure out a simple linear function

Maximum input to function is $40$, minimum is $1$. Function works like this:

$f(40)=0.2$,
$f(1)=1$

we also want to know what $f(x)$ would produce. The answer would be "linear" to these two cases - for example, $f(20)$ would return something around $0.6$.

Can someone help me with this function?

-

If $f$ is linear then $f(x)=ax+b$ for some $a,b$. Plug in the values $x=1$ and $x=40$ to obtain $a$ and $b$.

-
Thank you, this is the first, the shortest and the most universal answer and that's why I've chosen it. I'd like to thank the other two participants as well. – Primož Kralj Apr 15 '12 at 20:48

For linear $f$ we have $f(x) = a\cdot x + b$, so $0.2 = a \cdot 40 + b$ and $1 = a \cdot 1 + b$. Solving this set of equations we have that $a = \frac{-4}{195} = -0.0205128$ and $b = \frac{199}{195} = 1.02051$.

Hope that helps ;-)

-
Thank you, it helped :) – Primož Kralj Apr 15 '12 at 20:45

Since $f(1)=1$ and $f(40)=0.2$, and you want the function be linear, the output must decrease by $1-0.2=0.8$ units for every $40-1=39$ units of increase in the input. Therefore the output must decrease by $\dfrac{0.8}{39}$ units for every increase of $1$ in the input, and we have $$f(x)=1-\frac{0.8}{39}(x-1)=1-\frac8{390}(x-1)=1-\frac4{195}(x-1)\;.$$ If you want, you can simplify this to $$f(x)=\frac1{195}(199-4x)\;.$$

-
My calculations produced different constant, 199/195. – dtldarek Apr 15 '12 at 20:40
@dtldarek: sigh I really need to wake up. Thanks. – Brian M. Scott Apr 15 '12 at 20:43
Thank you for your straightforward answer. – Primož Kralj Apr 15 '12 at 20:46