0
$\begingroup$

I need a function that returns $0$ if the given number is negative, and otherwise doesn't change the number.

Example: $$y(-5)=0,\ y(-2)=0,\ y(0)=0,\ y(3)=3,\ y(2566)=2566.$$

Does such a function exist?

$\endgroup$
8
$\begingroup$

You can take for example $$\frac{|x|+x}{2}.$$ You can construct similar examples.

| cite | improve this answer | |
$\endgroup$
2
$\begingroup$

Exotic: $0^{\sqrt{x^2}-x}\cdot x$.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ It is undefined at 1 $\endgroup$ – MATHS MOD Apr 24 '19 at 14:44
  • $\begingroup$ Not if we agree upon $0^0=1$. $\endgroup$ – Michael Hoppe Apr 24 '19 at 15:00
  • $\begingroup$ Well that's a kind of cheating $\endgroup$ – MATHS MOD Apr 27 '19 at 2:57
2
$\begingroup$

Just use

$$f(x) = \max\{x,0\}$$

This way it's clear what your function do

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.