- Put the new value into z[0].
- Put z[0] into z[1] – now, what is z[0] at this point? Is it the old value (what you expected) or the new value (which you just put in).
You should copy the old value first, before overwriting it.
Next you’ll find that you’re getting the inverse derivative, because you’re doing old - new, where the derivative would be new - old.
Last, a note for forum usage: it helps people to read your code more accurately if you use markdown style for formatting: Code markup: Correct style
hjh