In the Numerical Recipes in section 5.7.- Numerical derivatives the choice of the step size $h$ in the numerical derivative should lead to a difference between $x$ and $x+h$ representable by an exact number. In C, the program steps are:

temp = x + h
h = temp - x

Question: What is the meaning of these steps?

Question: How can choose $h$ as an "exact" number in Matlab?


Gonna answer by points:

  1. NR authors are referring to the fact that $h$ itself is affected by roundoff too. Also, if your $h$ does not have a finite binary representation, like $h = 0.1$, you're sure you have error for every $h$ in your code.

What you really want is that the difference between $x$ and $x+h$ is exactly representable in finite precision arithmetic.

  1. Just do what they wrote: don't choose $h$ s.t. the increment in not exactly representable in finite precision. A good way could be to set $h= 2^{-k}$, for some $k \in \mathbb{N}$ (of course not too big...), so you know its representation is exact ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.