find $p$, $q$ such that $f$ is differentiable at zero I am trying to understand tasks like that
$$f(x)=\begin{cases} q+\sin(px)+qx &\text{for } x\ge0 \\ \frac{-1}{x\sin(x)} + \frac{\cos(x)}{x\sin(x)} &\text{for } x\in (-\pi,0)   \end{cases}$$
On my lecture I had theorem that
 $f$ is differentiable at zero if and only if exists finite:
$$ \lim_{h\rightarrow0} \frac{f(a+h)-f(a)}{h}= f'(a) $$

My current way of thinking
Ok, after small discussion in comments, I think that these conditions should be fulfilled:
1. $$ \lim_{h\rightarrow0^-} \frac{f(a+h)-f(a)}{h}=\lim_{h\rightarrow0^+} \frac{f(a+h)-f(a)}{h} $$ what is equal to:
 $$\lim_{x\rightarrow0^-}f'(x) = \lim_{x\rightarrow0^+} f'(x) $$


*Function should be continuous: 
$$\lim_{x\rightarrow0^-}f(x) = \lim_{x\rightarrow0^+} f(x) = f(0)$$

My current problem
I am trying to solve this with differential quotient but I stucked
$$ \lim_{h \to 0^-} \frac{f(h) - f(0)}{h} $$
there is a problem:(
 A: First observe that 
$$ \frac{\cos(x) - 1}{x \sin(x)} = \frac{\cos(x) - 1}{x^2} \cdot \frac{x}{\sin(x)} \longrightarrow -\frac 1 2 $$
for $x \to 0$. Moreover, it holds 
$q + \sin(px)  + qx \to q$. So since we need continuity of $f$ in the first place, one obtains $q = -\frac 1 2$. 
Now calculate the left and the right derivate in $0$ for the function 
$$f(x)=\begin{cases} -\frac 1 2+\sin(px)- \frac 1 2 x &\text{for } x\geq 0, \\ \frac{-1}{x\sin(x)} + \frac{\cos(x)}{x\sin(x)} &\text{for } x\in (-\pi,0).   \end{cases}$$
If you want $f$ to be differentiable in $x = 0$ you need to have $\lim_{h \to -0} \frac{f(h) - f(0)}{h} = \lim_{h \to +0} \frac{f(h) - f(0)}{h}$. This relation yields you then all possible values for $p$. 
A: Fix $p,q$ and assume $f'(0)$ exists. Then $f$ is continuous at $0.$ Because $f(0)=q,$ we must have $\lim_{x\to 0^-}f(x)=q.$ But
$$\lim_{x\to 0^-}f(x) = \lim_{x\to 0^-}\frac{\cos x-1}{x\sin x} = -\frac{1}{2}.$$
Therefore $q= -1/2.$
Now take $x>0$ and consider
$$\frac{f(x)-f(0)}{x}= \frac{-1/2 +\sin (px) -x/2 +1/2}{x} = \frac{\sin (px) - x/2}{x}.$$
The limit of this from the right is $p-1/2.$ This is the derivative of $f$ from the right at $0.$
Thus the derivative from the left equals $p-1/2.$ To find out what that implies, we look at the difference quotient from the left:
$$\frac{(\cos x-1)/(x\sin x)-(-1/2)}{x}= \frac{\cos x-1+(x\sin x)/2}{x^2\sin x}.$$
Using $\cos x = 1-x^2/2 + O(x^4)$ and $\sin x = x + O(x^3)$ shows the above equals
$$\frac{O(x^4)}{x^2\sin x}\to 0.$$
Thus the derivative from the left is $0.$ Therefore $p-1/2 = 0.$ So $p=1/2.$
Summary: Fixing $p,q$ and assuming $f'(0)$ exists, we showed $q=-1/2, p=1/2.$ We're not quite done though. Now we have to reason in the other direction: Assuming $q=-1/2, p=1/2,$ it follows that $f'(0)$ exists. This is simple, and I'll leave this to you for now.
