# Calculating derivative by definition vs not by definition

I'm not entirely sure I understand when I need to calculate a derivative using the definition and when I can do it normally. The following two examples confused me:

$$g(x) = \begin{cases} x^2\cdot \sin(\frac {1}{x}) & x \neq 0 \\ 0 & x=0 \end{cases}$$

$$f(x) = \begin{cases} e^{\frac {-1}{x}} & x > 0 \\ -x^2 & x\leq 0 \end{cases}$$

I understand that I can differentiate normally for any $x$ that's not 0 (in both of these examples). I'm confused because I saw an example with $f(x)$ in which they calculated the $f'(x)$ by differentiating:

$$f'(x) = \begin{cases} \frac {1}{x^2}\cdot e^{\frac {-1}{x}} & x > 0 \\ -2x & x\leq0 \end{cases}$$

and then they calculated $f'(0)$ not using the definition but by $\lim_{x\to0^-} f'(x)$ $\lim_{x\to0^+} f'(x)$

For $g(x)$ though I know that $g'(0)$ exists (using definition) but

$$g'(x) = \begin{cases} 2x\cdot \sin(\frac {1}{x})-\cos(\frac {1}{x}) & x \ne 0 \\ 0 & x=0 \end{cases}$$

and you can't calculate $\lim_{x\to0^-} g'(x)$ or $\lim_{x\to0^+} g'(x)$ since $\lim_{x\to0^{+/-}} 2x\cdot \sin(\frac {1}{x})-\cos(\frac {1}{x})$ doesn't exist.

So what's the difference between these two? When can I just differentiate normally like in the first example ($f(x)$) and when do I have to use the definition like in the second example ($g(x)$)?

I'd appreciate the help.

Edit: When I"m referring to the definition I'm referring to the following:

$\lim_{h \rightarrow 0} \dfrac{f(x+h) - f(x)}{h}$

-
$\lim _{x\to 0}f'(x)$ is not the definition of the derivative of $f$ at $0$, although it is the right answer if $f'$ is continuous at $0$. – rschwieb Jul 19 '13 at 20:27
What about if I want to check if it's continuous? Do I have to use the definition then? How could I have know that it's continuous without calculating the derivative at 0 without using the definition? – Shookie Jul 19 '13 at 20:51
You have to use the definition of continuity, yes... But nothing to do with the definition of the derivative. – rschwieb Jul 19 '13 at 22:43
It should be noted that all derivative computations come from the definition, it is a matter how much work one has to do to boil it down to the definition. – Baby Dragon Jul 20 '13 at 4:20

Given a function $f(x)$ and a point $x_0$, it's possible to take $f'(x_0)$ by differentiating normally only if $\lim\limits_{x \rightarrow x_0} f'(x)$ exists. However, this is not the case for the $g(x)$ that you gave.

As $x \rightarrow 0$, $-\cos\left(\frac{1}{x}\right)$ oscillates, and, in fact, in any small neighbourhood of $0$, there are points $y$ and $z$ such that $-\cos\left(\frac{1}{y}\right) = -1$ and $-\cos\left(\frac{1}{z}\right) = 1$. Thus, the limit as $x \rightarrow 0$ of this part of the function $g'(x)$ gotten by normal differentiation does not exist, and so the limit of the whole function does not exist, and therefore, it cannot be used as the derivative at that point. However, using the limit definition of the derivative, it is possible to find that $\frac{dg}{dx}(0) = 0$.

-
Does that mean the if the limit exists when differentiating normally exists then it's always okay? can it be that it exists but it's not the actual value? – Shookie Jul 19 '13 at 20:16
I'll think about that, and let you know if I get an answer, but I think you'd to better asking someone with better knowledge of analysis than me. I just know that certainly, if the limit doesn't exist, then you should use the definition. – qaphla Jul 19 '13 at 20:19

Neither of them is calling on the definition of derivatives (at least, not the normal one I think you're thinking of, the limit of the difference quotient.)

In both cases, you are calculuating the derivative "normally" (by which I think you mean through a pre-learned formula) to find out what the derivative of the function is on pieces of the real line.

The limits that appear in what you wrote are checking to see if this combined derivative is continuous near zero. You see, in principal the two derivatives that you get on each side might not match up at $0$, maybe one hits the $y$ axis lower than the other one hits the $y$ axis. In that case the derivative would have a jump discontinuity at $0$, and it wouldn't be continuous.

Actually, the example of $g$ that you have here is even wilder than that: it oscilates wildly on each side of $0$, causing it to have no defined limit as it approaches zero. Thus any computation of the limit from either side results in "undefined", and the derivative isn't continuous.

-
If I understand correctly you're saying that g'(x) isn't continues at 0 right? but if you try and calculate it using the definition then it is 0 while the cos(1/x) oscilates (which is why it doesn't work normally using the formula). – Shookie Jul 19 '13 at 20:31
Dear @Shookie : For me to best help you, I need you to write out the mathematical expression which is the definition you are referring to in the next comment. Thanks! – rschwieb Jul 19 '13 at 20:33
Maybe I'm misinterpreting; but derivatives can't have jump discontinuities. – David Mitra Jul 19 '13 at 20:36
@rschwieb : I've updated the original post as to what I consider as the definition. – Shookie Jul 19 '13 at 20:48
@rscwieb: What I'm asking is when I have to use the definition to get the correct value (like I needed to for g(x)) and when I can differentiate normally (like in f(x)) – Shookie Jul 19 '13 at 20:50

In what you quoted, the statement $f'(x)=-2x$ is valid only on $x<0$. The existence of $f'(0)$ must be determined from the definition. But read on.

Perhaps the following exercise will help you. Suppose $f$ is continuous on $(-a,a)$ and differentiable except perhaps at $0$. Suppose $$\lim_{x\to 0} f'(x)=L\,.$$ Then $f$ is differentiable at $0$ and $f'(0)=L$. (Hint: Use the Mean Value Theorem.)

Let me add the comment that the discussion in comments above begs the question: We can't say $f'$ is continuous at $0$ unless we first know it is defined there!

-