Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Numerical differentiation of
functions of two variables
So far, most of the functions we have encountered have only depended on one
variable, but both within mathematics and in applications there is often a need
for functions of several variables. In this chapter we will deduce methods for
numerical differentiation of functions of two variables. The methods are simple
extensions of the numerical differentiation methods for functions of one variable.
Definition 7.1 (Function of two variables). A (scalar) function f of two variables is a rule that to a pair of numbers (x, y) assigns a number f (x, y).
115
116
2.0
1.5
1.0
0.5
0.0
-1.0
1.0
1.0
0.5
0.0
-0.5
-0.5
0.0
0.5
1.0
0.5
0.0
-1.0
0.5
-0.5
0.0
1.0 -1.0
(a)
0.5
1.0
0.0
(b)
Figure 7.1. The plot in (a) shows the function f (x, y) = x 2 + y 2 with x and y varying in the interval [1, 1]. The
function in (b) is defined by the rule that f (x, y) = 0 except in a small area around the y-axis and the line y = 1,
where the value is f (x, y) = 1.
The obvious interpretation is that f (x, y) gives the height above the point in
the plane given by (x, y). This interpretation lets us plot functions of two variables, see figure 7.1.
The rule f can be given by a formula like f (x, y) = x 2 + y 2 , but this is not necessary, we just need to be able to determine f (x, y) from x and y. In figure 7.1 the
function in (a) is given by a formula, while the function in (b) is given by the rule
1, if |y 1| 0.1 and 1 x 1;
0, otherwise.
We will sometimes use vector notation and refer to (x, y) as the point x; then
f (x, y) can be written simply as f (x). There is also convenient notation for a set
of pairs of numbers that are assembled from two intervals.
Notation 7.2. Let the two sets of numbers A and B be given. The set of all
pairs of numbers from A and B is denoted A B,
A B = (a, b) | a A and b B .
7.1. BASICS
117
118
It turns out that for reasonable functions, the directional derivative can be
computed in terms of partial derivatives.
Theorem 7.6. Suppose the function is defined on the set A R2 and that a is
an interior point of A. If the two partial derivatives f /x and f /y exist in a
neighbourhood of a and are continuous at a, then the directional derivative
f 0 (a; r ) exists for all directions r = (r 1 , r 2 ) and
f 0 (a; r ) = r 1
f
f
(a) + r 2
(a).
x
y
The conditions in theorem 7.6 are not very strict, but should be kept in mind.
In particular you should be on guard when you need to compute directional
derivatives near points where the partial derivatives do not exist.
If we consider a function like f (x, y) = x 3 y + x 2 y 2 , the partial derivatives are
f /x = 3x 2 y + 2x y 2 and f /y = x 3 + 2x 2 y. Each of these can of course be
differentiated again,
2 f
= 6x y + 2y 2 ,
x 2
2 f
= 2x 2 ,
y 2
2 f
f
=
= 3x 2 + 4x y,
yx y x
f
2 f
=
= 3x 2 y + 4x y.
xy x y
We notice that the two mixed derivatives are equal. In general the derivatives
2 f
(a),
xy
2 f
(a)
yx
are equal if they both exist in a neighbourhood of a and are continuous at a. All
the functions we consider here have mixed derivatives that are equal. We can of
course consider partial derivatives of any order.
Notation 7.7 (Higher order derivatives). The expression
n+m f
x n y m
denotes the result of differentiating f , first m times with respect to y, and then
differentiating the result n times with respect to x.
7.1. BASICS
119
3
2
1
0
-1
4
3
2
1
0
-2
-1
0
1
2
Figure 7.2. An example of a parametric surface.
120
ometric form in computer programs for geometric design. These kinds of programs are used for designing cars, aircrafts and other industrial objects as well
as the 3D objects and characters in animated movies.
(7.1)
f (a, b + h 2 ) f (a, b) h 2 2 f
f
(a, b)
=
(a, c 2 ),
y
h2
2 y 2
(7.2)
g (a + h 1 ) g (a) h 1 00
+ g (c 1 )
h1
2
where c 1 is a number in the interval (a, a + h 1 ). From this the relation (7.1) follows.
121
(7.3)
,
x 2
h2
with error bounded by
4 f
h2
see exercise 9.11 in the Norwegian notes. These approximations of course work
equally well for non-mixed derivatives with respect to y.
Approximation of mixed derivatives requires that we use estimates for the
derivatives both in the x- and y-directions. This makes it more difficult to keep
track of the error. In fact, the easiest way to estimate the error is with the help
of Taylor polynomials with remainders for functions of two variables. However,
this is beyond the scope of these notes.
Let us consider an example of how an approximation to a mixed derivative
can be deduced.
Example 7.11. Let us consider the simplest mixed derivative,
2 f
(a, b).
xy
If we set
g (a) =
f
(a, b)
y
(7.4)
g (a + h 1 ) g (a h 1 )
.
2h 1
(7.5)
122
Now we can use the same kind of approximation for the two first-order partial
derivatives in (7.5),
f
f (a + h 1 , b + h 2 ) f (a + h 1 , b h 2 )
,
(a + h 1 , b)
y
2h 2
f
f (a h 1 , b + h 2 ) f (a h 1 , b h 2 )
(a h 1 , b)
.
y
2h 2
If we insert these expressions in (7.5) we obtain the final approximation
2 f
(a, b)
xy
f (a + h 1 , b + h 2 ) f (a + h 1 , b h 2 ) f (a h 1 , b + h 2 ) + f (a h 1 , b h 2 )
.
4h 1 h 2
If we introduce the notation
f (a h 1 , b h 2 ) = f 1,1 ,
f (a + h 1 , b h 2 ) = f 1,1 ,
f (a h 1 , b + h 2 ) = f 1,1 ,
f (a + h 1 , b + h 2 ) = f 1,1 ,
(7.6)
(7.7)
123
0
b h2
a h1
a + h1
Figure 7.3. The weights involved in computing the mixed second derivative with the approximation in example 7.11. This kind of figure is referred to as the computational molecule of the approximation.
Figure 7.4. Numerical approximations to partial derivatives are often computed at all points of a grid like the
one shown here by sliding around the grid a computational molecule like the one in figure 7.3.
124
the grid and computing the approximation at each point, as indicated by the
grey area in figure 7.4.
Exercises
7.1 In this exercise we are going to determine approximations to mixed derivatives.
.
x 2 y
8h 12 h 2
Hint: Use the approximation in (7.7).
b) Use the same technique as in (a) and deduce the approximation
4 f
x 2 y 2
f 2,2 2 f 0,2 + f 2,2 2 f 2,0 + 4 f 0,0 2 f 2,0 + f 2,2 2 f 0,2 + f 2,2
16h 12 h 22
4 f
,
x 2 y 2