2

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.

1 Answers1

1

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.

dbanet
  • 1,413
  • Just a clarification to the OP: the no here is an answer to the question "Do I need to change this formula?", while my yes in the comments is an answer to the question "Is this formula correct". – 5xum Oct 22 '15 at 18:30