Graphics Reference
In-Depth Information
constant is related to the
k
th derivative of
f
—and if
f
isn't particularly
smooth, that could be huge and the Taylor series (taken up to that term)
isn't particularly useful.
A.2.1
Finite Differences in Space
Partial derivatives of smooth functions sampled on a grid can be estimated
using Taylor's theorem. For example, for a function
q
(
x
) sampled at grid
points spaced Δ
x
apart, i.e.,
q
i
=
q
(
x
i
)=
q
(
i
Δ
x
), Taylor's theorem gives
q
i
+1
=
q
i
+Δ
x
∂q
∂x
(
x
i
)+
O
(Δ
x
2
)
.
We can rearrange this to get an estimate of
∂q/∂x
at
x
i
:
∂q
∂x
(
x
i
)=
q
i
+1
−
q
i
+
O
(Δ
x
)
.
Δ
x
Note that after dividing through by Δ
x
, the error term was reduced to
first
order
, i.e., the exponent of Δ
x
in the
O
() notation is one.
Of course, you can also estimate the same derivative from
q
i−
1
,using
Taylor's theorem for
q
i−
1
=
q
(
x
i−
1
):
∂q
∂x
(
x
i
)=
q
i
−
q
i−
1
Δ
x
+
O
(Δ
x
)
.
This is also only first-order accurate. Both this and the previous finite dif-
ference are
one-sided
, since values of
q
only to one side of the approximation
point are used.
We can get second-order accuracy by using both
q
i
+1
and
q
i−
1
,fora
centered
or
central
finite difference: the value we're approximating lies in
the center of the points we use. Write down the Taylor series for both these
points:
q
i
+1
=
q
i
+Δ
x
∂q
∂x
(
x
i
)+
Δ
x
2
∂
2
q
∂x
2
(
x
i
)+
O
(Δ
x
3
)
,
2
∂
2
q
∂x
2
(
x
i
)+
O
(Δ
x
3
)
.
Now subtract them to get, after cancellation,
∂x
(
x
i
)+
Δ
x
2
Δ
x
∂q
q
i−
1
=
q
i
−
2
q
i−
1
=2Δ
x
∂q
∂x
(
x
i
)+
O
(Δ
x
3
)
.
q
i
+1
−
Dividing through gives the second-order accurate central finite difference:
∂q
∂x
(
x
i
)=
q
i
+1
−
q
i−
1
2Δ
x
+
O
(Δ
x
2
)
.