Numerical derivative of compoiste function
sorry for the very basic question. I am writing a Fortran program in which I have a quite complicated function in a non-linear system of equations and I need to differentiate it numerically in order to get a member of the Jacobian for solving the system with the Newton-Raphson method. The question is... being a composite function like
$$g(f(x))$$
is the numerical derivative (central difference formula) simply:
$$ \dfrac{\partial g(f(x))}{\partial x} = \dfrac{g(f(x+h)) - g(f(x-h))}{2h}$$
?
Do I need to change this formula according to the chain rule?
Regards.
$\endgroup$ 11 Answer
$\begingroup$No.
You have $$F(x)=g(f(x))$$ and want to find $$\frac{\mathrm dF(x)}{\mathrm dx}.$$
By definition, $$\frac{\mathrm dF(x)}{\mathrm dx}=\lim_{h\to0}\frac{F(x+h)-F(x)}{h}$$ or, almost equivalently, $$\lim_{h\to0}\frac{F(x+h)-F(x-h)}{2h}.$$
Now, given the definition of $F$ as $F(x)=g(f(x))$, evaluate: $$\frac{F(x+h)-F(x-h)}{2h}=\frac{g(f(x+h))-g(f(x-h))}{2h}.$$
Taking the limit will give the derivative or substituting a small $h$ will give a numerical approximation to it, no matter if $F$ is constructed via composition of two functions or not.
$\endgroup$ 1More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"