# Continuity and differentiability of a piecewise function

Let

$$f(x) = \begin{cases} \phantom{-}3x^2 & : x \in \mathbb{Q^c}\\ -5x^2 & : x \in \mathbb{Q} \end{cases}$$

Where is $f(x)$ continuous? Is $f(x)$ differentiable anywhere?

Attempt:

I think $f(x)$ will be continuous at $0$ since $f(x)=-5(0)^2=0$ and I can always find a sequence of irrational numbers that will converge to $0$ so that $f(x)=3(0)^2=0$. However, I am not completely sure if this is the right approach to the question. Furthermore, I am unclear as to the differentiability of $f(x)$ at $0$.

• What is the derivative of f(x) at 0? Can you take it? – cygorx Oct 13 '13 at 22:06
• The fact that you can find ONE sequence of irrational numbers converging to $0$ isn't enough; you need to know that EVERY sequence of irrational numbers converging to $0$ has a sequence of images under $f$ converging to $0$. (But that's not hard to show.) – Michael Hardy Oct 13 '13 at 22:22

You're right about $f$ being continuous at $x=0$, but your proof is wrong as noted by Michael Hardy in his comment. Below I prove that $f$ is differentiable at $x=0$ and hence continuous there.
It can be proved that $f$ isn't continuous at $x\neq 0$ because for any given $x\neq 0$ you can find a sequence of rational numbers that converges to $x$ and a sequence of irrational numbers that also convergers to $x$ and by taking limits you can see that they will differ.
As for differentiability it can only be differentiable at $x=0$, if at any point at all.
Let $h\in \Bbb R$.
We get $\dfrac{f(0+h)-f(0)}{h}=\begin{cases} 3h, &\text{ if }h\text{ is irrational}\\ -5h, &\text{ if }h \text{ is rational}\end{cases}$ and as $h\longrightarrow 0$ we get $0$, hence $f$ is differentiable at $0$ and $f'(0)=0$.