I have this function $$A_x=A_0\frac{1}{1+e^{-az}}e^{ik(z-ct)}$$ where $A_0$ is a constant and $a$ and $k$ are constants with dimensions of inverse length and $z \in \mathbb{R}$
I wish to compute $$\frac{\partial^2 A_x}{\partial z^2}$$
So my attempt is
$$\frac{\partial^2 A_x}{\partial z^2}=A_0\left[\frac{\partial^2}{\partial z^2} \left(\frac{1}{1+e^{-az}}\right)-\frac{k^2}{1+e^{-az}}\right]e^{ik\left(z-ct \right)}$$
where I have simply applied the product rule for differentiation making the assumption that it works for double derivatives.
The reason why I have done it this way is to simplify the calculation further by using the following result:
$$\frac{\partial^2}{\partial z^2}\left(\frac{1}{1+e^{-az}}\right)=a^2\frac{e^{-az}\left(e^{-az}-1\right)}{\left(1+e^{-az}\right)^3}$$
The problem, however, is that the correct answer is
$$\frac{\partial^2 A_x}{\partial z^2}=A_0\left[\frac{\partial^2}{\partial z^2} \left(\frac{1}{1+e^{-az}}\right)+\color{blue}{2ik\frac{\partial}{\partial z}\left(\frac{1}{1+e^{-az}}\right)}-\frac{k^2}{1+e^{-az}}\right]e^{ik\left(z-ct \right)}$$
My answer is identical with the exception of the blue term, I don't understand where this term comes from and I know that my answer is wrong, but I would like to know where this term comes from and hence why the product rule does not apply to double derivatives?
$\endgroup$ 54 Answers
$\begingroup$The product rule is slightly different for double derivatives. For simplicity, let $f$ and $g$ be twice continuously differentiable functions of $x$. Then,
$$\frac{d^2}{dx^2}fg = \frac{d}{dx}\left(\frac{d}{dx}fg\right) = \frac{d}{dx}\left(f'g + fg'\right) = \frac{d}{dx}f'g + \frac{d}{dx}fg' = f''g + f'g' + f'g' + fg'' = f''g + \mathbf{2f'g'} + fg''.$$
The bold term corresponds to the blue term missing from your answer.
By the way, you can extend this to higher order derivatives in the same way. You end up with,
$$\frac{d^n}{dx^n}fg = \sum_{k=0}^n \binom{n}{k}f^{(n-k)}g^{(k)}.$$
edit: fixed typo
$\endgroup$ 1 $\begingroup$The notation
$$\frac{\partial^2 f}{\partial x^2}$$
is an abbreviation of
$$\frac{\partial}{\partial x}\left(\frac{\partial f}{\partial x}\right)$$
which is where you are confused. It means differentiate twice. Try this and you'll get the right answer.
$\endgroup$ 2 $\begingroup$Assuming no other variable apart from $A_x$ depends on $z,$ then we may simplify the result as (I'll set $A_x=A$) $$A=G\frac{1}{e^{mz}+e^{nz}},$$ where $G=A_0e^{-ikct},\,\,m=-ik$ and $n=-a-ik.$
Then we have that $$A'_z=\frac{-G(me^{mz}+ne^{nz})}{(e^{mz}+e^{nz})^2}.$$ If you now differentiate again (to do this easily split $A'_z$ into two parts and reduce the numerator of each summand to a constant by the above trick; that's better than applying the quotient rule here), and then back-substitute, you'll find this more easy to operate with, and errors easier to track.
$\endgroup$ $\begingroup$To get the product rule for a second derivative, first start with the product rule for a first derivative:$$(fg)' = f' g + f g'.$$Then, take the derivative again:$$(fg)'' = (f' g)' + (f g')' = [f'' g + f' g'] + [f' g' + f g''] = f'' g + 2 f' g' + f g''.$$
For higher-order derivatives, we get a general result which can be similarly proved by induction:
$$(fg)^{(n)} = \sum_{k=0}^n \binom{n}{k} f^{(n-k)} g^{(k)}.$$
Incidentally, since you mentioned partial derivatives, there is a further generalization of the above formula using the language of multi-indices, which will also allow you to calculate mixed derivatives of a product:
$$\frac{\partial^N}{\partial x^N} (fg) = \sum_{K \le N} \binom{N}{K} \frac{\partial^{N-K} f}{\partial x^{N-K}} \cdot \frac{\partial^K g}{\partial x^K}.$$
Here, if $f, g$ are functions of $x_1, \ldots, x_r$, and $N = (n_1, \ldots, n_r)$, then:$$\frac{\partial^N f}{\partial x^N} = \frac{\partial^{n_1 + \cdots + n_r} f}{\partial x_1^{n_1} \cdots \partial x_r^{n_r}};\\ K \le N \iff k_1 \le n_1 \wedge \cdots \wedge k_r \le n_r; \\ \binom{N}{K} = \binom{n_1}{k_1} \cdots \binom{n_r}{k_r}.$$So for example, if we had functions $f, g$ of $x, y$ and we wanted to calculate $\frac{\partial^3}{\partial x \partial^2 y}(f g)$, then we would apply the formula with $N = (1, 2)$. The sum would involve six values of $K$, $(0,0), (0,1), (0,2), (1,0), (1,1), (1,2)$, and the end result would be:$$(fg)_{xyy} = f_{xyy} g + 2 f_{xy} g_y + f_x g_{yy} + f_{yy} g_x + 2 f_y g_{xy} + f g_{xyy}.$$
$\endgroup$ 1