Skip to article frontmatterSkip to article content

Tensor-product discretizations

As you learned when starting double integration in vector calculus, the simplest extension of an interval to two dimensions is a rectangle. We will use a particular notation for rectangles:

[a,b]×[c,d]={(x,y)R2:axb,  cyd}. [a,b] \times [c,d] = \bigl\{ (x,y)\in\mathbb{R}^2 : a\le x \le b,\; c\le y \le d \bigr\}.

The × in this notation is called a tensor product, and a rectangle is the fundamental example of a tensor-product domain. The implication of the tensor product is that each variable independently varies over a fixed set. The simplest three-dimensional tensor-product domain is the cuboid [a,b]×[c,d]×[e,f][a,b]\times[c,d]\times[e,f]. When the interval is the same in each dimension (that is, the region is a square or a cube), we may write [a,b]2[a,b]^2 or [a,b]3[a,b]^3. We will limit our discussion to two dimensions henceforth.

The discretization of a two-dimensional tensor-product domain is straightforward.

13.1.1Functions on grids

The double indexing of the grid set (13.1.3) implies an irresistible connection to matrices. Corresponding to any function f(x,y)f(x,y) defined on the rectangle is an (m+1)×(n+1)(m+1)\times(n+1) matrix F\mathbf{F} defined by collecting the values of ff at the points in the grid. This transformation of a function to a matrix is so important that we give it a formal name:

F=mtx(f)=[f(xi,yj)]i=0,,mj=0,,n.\mathbf{F} = \mtx(f) = \Bigl[f(x_i,y_j)\Bigr]_{\substack{i=0,\ldots,m\\j=0,\ldots,n}}.

13.1.2Parameterized surfaces

We are not limited to rectangles by tensor products. Many regions and surfaces may be parameterized by means of x(u,v)x(u,v), y(u,v)y(u,v), and z(u,v)z(u,v), where uu and vv lie in a rectangle. Such “logically rectangular” surfaces include the unit disk,

{x=ucosv,y=usinv,0u<1,0v2π,\left\{ \begin{aligned} x &= u \cos v, \\ y &= u \sin v,\\ \end{aligned} \right. \qquad \qquad \left. \begin{aligned} 0 & \le u < 1, \\ 0 &\le v \le 2\pi, \end{aligned} \right.

and the unit sphere,

{x=cosusinv,y=sinusinv,z=cosv,0u<2π,0vπ.\left\{ \begin{aligned} x &= \cos u \sin v,\\ y &= \sin u \sin v,\\ z &= \cos v, \end{aligned} \right. \qquad \qquad \left. \begin{aligned} 0 & \le u < 2\pi, \\ 0 &\le v \le \pi. \end{aligned} \right.

13.1.3Partial derivatives

In order to solve boundary-value problems in one dimension by collocation, we replaced an unknown function u(x)u(x) by a vector of its values at selected nodes and discretized the derivatives in the equation using differentiation matrices. We use the same ideas in the 2D case: we represent a function by its values on a grid, and multiplication by differentiation matrices to construct discrete analogs of the partial derivatives ux\frac{\partial u}{\partial x} and uy\frac{\partial u}{\partial y}.

Consider first ux\frac{\partial u}{\partial x}. In the definition of this partial derivative, the independent variable yy is held constant. Note that yy is constant within each column of U=mtx(u)\mathbf{U} = \mtx(u). Thus, we may regard a single column uj\mathbf{u}_j as a discretized function of xx and, as usual, left-multiply by a differentiation matrix Dx\mathbf{D}_x such as (10.3.6). We need to do this for each column of U\mathbf{U} by Dx\mathbf{D}_x, which is accomplished by DxU\mathbf{D}_x \mathbf{U}. Altogether,

mtx(ux)Dxmtx(u). \mtx\left( \frac{\partial u}{\partial x} \right) \approx \mathbf{D}_x \, \mtx(u).

This relation is not an equality, because the left-hand side is a discretization of the exact partial derivative, while the right-hand side is a finite-difference approximation. Yet it is a natural analog for partial differentiation when we are given not u(x,y)u(x,y) but only the grid value matrix U\mathbf{U}.

Now we tackle uy\frac{\partial u}{\partial y}. Here the inactive coordinate xx is held fixed within each row of U\mathbf{U}. However, if we transpose U\mathbf{U}, then the roles of rows and columns are swapped, and now yy varies independently down each column. This is analogous to the situation for the xx-derivative, so we left-multiply by a finite-difference matrix Dy\mathbf{D}_y, and then transpose the entire result to restore the roles of xx and yy in the grid. Fortunately, linear algebra allows us to express the sequence transpose–left-multiply–transpose more compactly:

mtx(uy)(DyUT)T=mtx(u)DyT.\mtx\left( \frac{\partial u}{\partial y} \right) \approx \Bigl(\mathbf{D}_y \mathbf{U}^T\Bigr)^T = \mtx(u)\, \mathbf{D}_y^T.

Keep in mind that the differentiation matrix Dx\mathbf{D}_x is based on the discretization x0,,xmx_0,\ldots,x_m, and as such it must be (m+1)×(m+1)(m+1)\times (m+1). On the other hand, Dy\mathbf{D}_y is based on y0,,yny_0,\ldots,y_n and is (n+1)×(n+1)(n+1)\times (n+1). This is exactly what is needed dimensionally to make the products in (13.1.8) and (13.1.9) consistent. More subtly, if the differentiation is based on equispaced grids in each variable, the value of hh in a formula such as (5.4.8) will be different for Dx\mathbf{D}_x and Dy\mathbf{D}_y.

13.1.4Exercises

  1. ⌨ In each part, make side-by-side surface and contour plots of the given function over the given domain.

    (a) f(x,y)=2y+exyf(x,y) = 2y + e^{x-y}, [0,2]×[1,1]\quad[0,2]\times[-1,1]

    (b) f(x,y)=tanh[5(x+xyy3)]f(x,y) = \tanh[5(x+xy-y^3)], [2,2]×[1,1]\quad[-2,2]\times[-1,1]

    (c) f(x,y)=exp[6(x2+y21)2]f(x,y) = \exp \bigl[-6(x^2+y^2-1)^2 \bigr], [2,2]×[2,2]\quad[-2,2]\times[-2,2]

  2. ⌨ For each function in Exercise 1, make side-by-side surface plots of fxf_x and fyf_y using Chebyshev spectral differentiation.

  3. ⌨ For each function in Exercise 1, make a contour plot of the mixed derivative fxyf_{xy} using Chebyshev spectral differentiation.

  4. ⌨ In each case, make a plot of the function given in polar or Cartesian coordinates over the unit disk.

    (a) f(r,θ)=r22rcosθf(r,\theta) = r^2 - 2r\cos \theta

    (b) f(r,θ)=e10r2f(r,\theta) = e^{-10r^2}

    (c) f(x,y)=xy2sin(x)f(x,y) = xy - 2 \sin (x)

  5. ⌨ Plot f(x,y,z)=xyxzyzf(x,y,z)=x y - x z - y z as a function on the unit sphere.

  6. ⌨ Plot f(x,y,z)=xyxzyzf(x,y,z)=x y - x z - y z as a function on the cylinder r=1r=1 for 1z2-1\le z \le 2.