0

A user on the chat asked how could he make something that would cap when it gets a specific value like 20. Then the behavior would be as follows:

$f(...)=...$

$f(18)=18$

$f(19)=19$

$f(20)=20$

$f(21)=20$

$f(22)=20$

$f(...)=20$

He said he would like to perform it with a regular calculator. Is it possible to do this?

Red Banana
  • 23,956
  • 20
  • 91
  • 192
  • 2
    Could you better explain your problem? – Sigur Aug 20 '12 at 12:47
  • Well, I guess you are not looking for the function $f(x)$ which returns $x$ when $x$ is less than 20, and 20 otherwise. – utdiscant Aug 20 '12 at 12:48
  • 2
    Your use of "=" has so many people rolling in their graves now I think you have triggered the mathematician zombie apocalypse. Do you mean something like capping a sequence $f(1),f(2),f(3)\dots$? – rschwieb Aug 20 '12 at 12:49
  • 14
    From here: $$\frac{x+20-|x-20|}{2}$$ – J. M. ain't a mathematician Aug 20 '12 at 12:49
  • @utdiscant What is this function? – Red Banana Aug 20 '12 at 12:50
  • Calculators might have $min(x,20)$? – rschwieb Aug 20 '12 at 12:52
  • @rschwieb 1 - Why the problem with the $=$? 2 - Yep, that's what I want. – Red Banana Aug 20 '12 at 12:52
  • @GustavoBandeira it belongs to a Piecewise function. Looks something like this. – Frenzy Li Aug 20 '12 at 12:52
  • $f(x) = \min(x,20)$ – Mark Bennet Aug 20 '12 at 12:53
  • @FrenzYDT. That's a problem. Piecewise functions work with conditionals, he wants it without conditionals. – Red Banana Aug 20 '12 at 12:53
  • Should we add a [tag:calculator] tag? – Frenzy Li Aug 20 '12 at 12:56
  • 4
    @GustavoBandeira You shouldn't put "=" between quantities that aren't equal. If you do, you have a false statement. Writing "22=20" is as absurd as writing "0=1". – rschwieb Aug 20 '12 at 13:07
  • @rschwieb I like to be experimental, dude. – Red Banana Aug 20 '12 at 17:07
  • 1
    @GustavoBandeira Quick fact: misunderstanding the equals sign cripples the math ability and development of students at many levels (no kidding). A good portion of them (mistakenly) think that this problem "isn't important". Take it seriously! – rschwieb Aug 20 '12 at 17:12
  • @rschwieb I take it seriously. But at this context, I needed something to express this. I guess it would be better to: $f(19)=20$, $f(20)=20$, $f(21)=20$, $...$ – Red Banana Aug 20 '12 at 17:16
  • 3
    @GustavoBandeira Yeah, that's a much better version :) People will understand you more quickly. – rschwieb Aug 20 '12 at 17:17
  • @J.M. You should give it as a answer because it is the answer. I've noticed it won't work for the negative numbers, is it possible to make a more general form including the integers? – Red Banana Aug 20 '12 at 20:07
  • 1
    @Gustavo: It seems to me that J.M.'s formula works for all numbers. What makes you think it wouldn't for negative numbers? – Jyrki Lahtonen Aug 20 '12 at 20:17
  • 1
    Great, not only is this turning into an obfuscated formula competition, but people are ignoring the part where "he said he would like to perform it with a regular calculator." –  Aug 20 '12 at 22:26
  • Of course if you chose a moderately large, but finite $n$ ($n=10$ is already quite good), my formula can be used on a standard scientific calculator. While it only gives an approximation, only for values near $x=20$ the approximation differs from the exact value less than the numeric error. However, for too small $x$ you may get an overflow. – celtschk Aug 21 '12 at 08:14

3 Answers3

9

$ x \mapsto \min ( x , 20 ) $

1

We can also get a bit (unnecessarily) fancier: $$ f(x) = x + (20 - x) \int\limits_{-\infty}^{x-20} \delta(t)\ dt $$ where $$ \int\limits_{-\infty}^{x-20} \delta(t)\ dt = \begin{cases} 0 & x < 20 \\ 1 & x \ge 20 \end{cases} $$ (See Heaviside step function.)

0

While we are at fancy expressions, what about $$20-\lim_{n\to\infty}\frac1n\ln\left(1+\mathrm e^{n(20-x)}\right)$$

celtschk
  • 43,384