Example of a function $f$ which is nowhere continuous but $|f|$ should be continuous at all points

4.1k Views Asked by At

So I had an exam today and one of the questions were: Give an example of a function $f$ which is nowhere continuous but $|f|$ should be continuous at all points. At first I had no idea how to do it then I came up with this, even though I know it's wrong:

$$f(x)= \begin {cases} \ \sqrt{x}&\text{if }x <0\\ \sqrt{-x}\ &\text{if }x > 0\\ \end {cases}$$

Like I said I know it's wrong..but can someone give me an example of this? Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

Let $$f(x)=\begin{cases}1,&\text{if }x\in\Bbb Q\\-1,&\text{if }x\in\Bbb R\setminus\Bbb Q\;.\end{cases}$$

There are many variations on this, but this is one of the simplest.