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.
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.