I decided to go ahead and attempt one of my problem sets early, and I found that in the process, I needed to come up with an order two FD approximation to
. Generally when I come across a question like this, it usually just asks for a 2nd order approximation to say the 1st derivative, and then I just mess around with various combinations of Taylor series expansions of the type
, until I hit upon what I need.
Even for that relatively simple case, this procedure is a pain in the ass. I didn’t think I was up to it for the 3rd derivative, so I came up with a more systematic procedure, which can be used to get
with accuracy
. It gives a forward finite differences scheme, but the idea should be adaptable to backward and central difference schemes also.
Here’s the idea: let
be a weight by which we will multiply
. Then
so
Letting
, what we want is
, because if this holds true,
which would imply
as desired.
So the question is how do we choose
and
such that we have the appropriate conditions on
? Well, note that if we write
and
as vectors, we have
where
. Conveniently, when such an
is square, it is full rank (prove it!), so we can invert to find the weights. Since
varies between
and
, letting
contain
to
makes
square.
Voila! (I’d like to say Q.E.D., but this was an algorithm, not a proof
)
To recap, if you want to approximate
with accuracy
using forward differences, use the
point approximation
where the weight vector
is chosen to satisfy
where
and the 1 is in the
-th entry of the rhs vector.
Of course, you better check all my algebra if you intend to use this for anything important. I’m sure I messed up somewhere– I tried coding this up in Mathematica to test it and got weird results– but I’ve spent enough time on it for now.