0% found this document useful (0 votes)
423 views23 pages

Jacobian Matrix PDF

This document presents a direct matrix method for analytically computing the Jacobian of nonlinear algebraic equations that arise from discretizing nonlinear integro-differential equations. The method formulates the discretized equations in vector form using only matrix-vector products and component-wise operations. By applying simple matrix-based differentiation rules, the analytical Jacobian can be calculated directly in matrix form, similar to computing derivatives in single-variable calculus. The method is then applied to examples involving Nernst-Planck equations for ion transport.

Uploaded by

Rajesh Malik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
423 views23 pages

Jacobian Matrix PDF

This document presents a direct matrix method for analytically computing the Jacobian of nonlinear algebraic equations that arise from discretizing nonlinear integro-differential equations. The method formulates the discretized equations in vector form using only matrix-vector products and component-wise operations. By applying simple matrix-based differentiation rules, the analytical Jacobian can be calculated directly in matrix form, similar to computing derivatives in single-variable calculus. The method is then applied to examples involving Nernst-Planck equations for ion transport.

Uploaded by

Rajesh Malik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

A SIMPLE DIRECT MATRIX APPROACH FOR COMPUTING

JACOBIANS OF NONLINEAR DISCRETIZED


INTEGRO-DIFFERENTIAL EQUATIONS
KEVIN T. CHU†

Abstract. In this article, we present a simple direct matrix method for analytically computing
the Jacobian of nonlinear algebraic equations that arise from the discretization of nonlinear integro-
differential equations. This method is based on a formulation of the discretized equations in vector
arXiv:math.NA/0702116v1 5 Feb 2007

form using only matrix-vector products and component-wise operations. By applying simple matrix-
based differentiation rules, we are able to calculate the analytical Jacobian of the discretized equations
directly in matrix form in a manner reminiscent of computing derivatives in single-variable calculus.
After presenting the method, we briefly discuss its connection to the Newton-Kantorovich method
(also known as quasilinearization) for numerically solving nonlinear integro-differential equations and
apply it to a few example problems.

Key words. analytical Jacobian, numerical methods, matrix calculus, Newton’s method,
integro-differential equations

AMS subject classifications. 65-01, 65L10, 65N22

Introduction. Many numerical methods for solving nonlinear integro-differential


equations require computation of the Jacobian for the nonlinear system of algebraic
equations that arises when a continuous problem is discretized. For example, any
Newton’s method calculation requires computation of the Jacobian (exactly or ap-
proximately) during each Newton iteration [1, 2]. Unfortunately, calculation of the
Jacobian can be a time-consuming and error-prone procedure for both the computer
and the scientific programmer.
One common approach for obtaining the Jacobian of a discretized, nonlinear
differential equation is to compute it numerically [1, 2]. The idea is to approximate the
partial derivatives of the residual function using finite differences obtained by slightly
perturbing the current iterate of the solution. For grid function based methods (e.g.,
finite difference and pseudospectral methods [3, 4, 5]) and series expansion based
methods (e.g., finite element [6, 7] and spectral methods [8]), the perturbations are
very small changes in the value of the solution at a grid point and the expansion
coefficients, respectively. Unfortunately, numerical computation of the Jacobian can
be very time consuming for some problems. Depending on the numerical method,
it might be possible to reduce the computational cost of a numerical Jacobian by
taking advantage of the sparsity pattern in the Jacobian [1, 9, 10]. These approaches,
however, are typically limited to low-order numerical discretizations.
As an example, consider the following time-dependent system of differential equa-
tions from the field of electrochemical transport:
∂c+
(0.1) = ∇ · (∇c+ + c+ ∇φ)
∂t
∂c−
(0.2) = ∇ · (∇c− − c− ∇φ)
∂t
where c± are cation and anion concentrations, respectively, and φ is the electric
potential. These are the Nernst-Planck equations for ion transport and are simply
† Department of Mechanical and Aerospace Engineering, Princeton University, Princeton, NJ

08544
1
2 KEVIN T. CHU

conservation laws for cations and anions [11, 12]. Closure of this system of equations
is provided by the Poisson equation [13]

(0.3) ǫ∇2 φ = − (c+ − c− ) ,

where ǫ is a dimensionless physical parameter related to the dielectric constant of


the electrolyte. Note that in (0.3), the local charge density has been written in
terms of the individual ions, which are the only source of charge density in many
electrochemical systems. (0.1) – (0.3) form a nonlinear parabolic system of partial
differential equations, which suggests that we use an implicit time-stepping scheme
to numerically solve the equations. This choice, however, requires that at time tn+1 ,
(n+1)
we solve a nonlinear system of equations for c± which depends on an auxiliary
(n+1)
variable φ which is related to c± through the Poisson equation. Note that in order
to numerically compute the Jacobian for the resulting nonlinear system of equations
(n+1)
for c± , we must solve the Poisson equation for each perturbation to the current
(n+1)
iterate of c± . Since the discretized form of (0.3) is a simple linear system of
equations, we can numerically solve for φ on a grid containing a total of N grid
points in O(N 3 ) operations using Gaussian elimination1 [14, 15]. Thus, numerically
computing the Jacobian requires a total of O(N 4 ) operations – one solution of the
Poisson equation for for each of the N grid point perturbations – which is rather large
considering that there are only N 2 entries in the Jacobian matrix.
To avoid the cost associated with numerical Jacobians, we can use an analytical
Jacobian for the discretized form of the nonlinear integro-differential equation. In
principle, it is straightforward to calculate the analytical Jacobian for the nonlinear
system of algebraic equations that arises when a nonlinear differential equation is
discretized. Index notation (also known as tensor notation) is perhaps the most
common technique used to calculate analytical Jacobians. The basic idea behind the
index notation method is to write the discretized form of the differential equation using
index notation and then use tensor calculus to compute individual matrix elements
in the Jacobian. For example, for a finite-difference or pseudospectral discretization
of the nonlinear integro-differential equation, the discretized equations can be written
in the form:

(0.4) Fi (u1 , u2 , . . . , uN ) = 0

for i = 1, 2, . . . , N where ui and Fi are the value of the solution and the discretized
differential equation at the i-th grid point (or more generally, the i-th collocation
point). Boundary conditions are included in this formulation by using the discretized
boundary conditions (rather than the integro-differential equation) at grid points on
the boundary (or immediately adjacent to if no grid points reside on the boundary).
The ij-th element of the Jacobian, J, for (0.4) is simply the partial derivative of
Fi with respect to uj : Jij = ∂Fi /∂uj . For simple problems, it may be possible to
examine the individual elements, Jij , and convert the element-wise representation of
the Jacobian back into matrix form. Interestingly, this last step often reveals the
close relationship between the Jacobian for the discrete equations and the underlying
structure of the original integro-differential equation.

1 The O(N 3 ) operation count is necessary only for high-order pseudospectral discretizations. For

low-order discretizations, this asymptotic operation count may be significantly reduced at the cost
of requiring more grid points to obtain an accurate solution.
DIRECT MATRIX METHOD FOR NONLIN. INTEGRO-DIFF. EQs 3

While simple and straightforward, index notation suffers from the disadvantage of
being somewhat tedious and error-prone. The main challenge in using index notation
is keeping track of all of the indices when writing out and computing partial deriva-
tives of the discrete equations. These challenges may partially explain why analytical
Jacobians are not more common in scientific computing.
In this article, we present a simple direct matrix method for calculating analytical
Jacobians of discretized, nonlinear integro-differential equations. Unlike the index
notation method, the direct matrix method produces the Jacobian for the discretized
equations directly in matrix form without resorting to computation of individual ma-
trix elements. The essential ideas are to first write the discretized, integro-differential
equation explicitly in terms of discrete operators (e.g., differentiation and quadrature
matrices [3, 4, 5]) and then use simple matrix -based differentiation rules to calculate
the Jacobian directly [16, 17, 18]. The key observation underlying this approach is
that there is a tremendous amount of structure in the nonlinear algebraic equations
that arise from the discretization of nonlinear integro-differential equations. By tak-
ing advantage of this structure, the calculation of analytical Jacobians is reduced to
nearly the level of complexity required to compute derivatives of scalar, single variable
functions.
The matrix-based approach of expressing and analyzing discretized differential
equations has been used implicitly by various authors over the past several decades
but seems to have been first formalized as a collection of rules by Chen [16, 19] who
formulated the method in terms of specially defined matrix products. In addition to
using the method to solve nonlinear partial differential equations [17, 20, 21], Chen
used his formulation of the method to develop several interesting theoretical results
(e.g. stability analysis of numerical methods for nonlinear time-dependent problems)
based on the observation that when a nonlinear differential equation only has polyno-
mial nonlinearities, there is a very close relationship between the discretized nonlinear
differential equation and its Jacobian [16, 22].
The present formulation of the direct matrix method is mathematically equivalent
to Chen’s approach. The main distinction lies in our reliance only on standard linear
algebra operations augmented by component-wise operations (e.g., the Hadamard or
Schur product [23]) and our emphasis on the analogy between calculation of derivatives
for scalar functions of a single variable and calculation of Jacobians for discretized,
nonlinear integro-differential equations. The analogy to single-variable calculus is
made especially clear by organizing the operations required to compute a Jacobian as
a short list of simple differentiation rules.
The direct matrix method has several advantages over other methods for calcu-
lating the analytical Jacobian of discretized, nonlinear integro-differential equations.
First, because the method is based on simple differentiation rules, the calculation is
straightforward and less prone to error. Also, as will be demonstrated later, the differ-
entiation rules make it much easier to calculate the Jacobian for differential equations
which depend on auxiliary variables, such as (0.1) – (0.3). From a programming
perspective, calculation of the Jacobian directly in matrix form facilitates implemen-
tation of numerical methods for nonlinear problems in languages that have built-in
support for matrix and vector operations (e.g., MATLAB and Fortran 95). Finally,
having the Jacobian available in matrix form can be useful for analyzing properties
of numerical methods [16].
It is important to mention that the direct matrix method is restricted to dis-
cretized equations that can be expressed in terms of matrix-vector products and
4 KEVIN T. CHU

component-wise operations, so it is only applicable to integro-differential equations


that are composed of linear operators and point-wise algebraic or transcendental op-
erations. Fortunately, many important integro-differential equations fall into this
category.
Because of its prevalence in modern scientific computing, we shall use MATLAB
notation in our formulation and discussion of the direct matrix method. In addition
to being a common language for numerical computing, MATLAB is quite capable
of handling moderate-sized production work (especially on today’s powerful desktop
and laptop machines). Thus, working in MATLAB notation has the added benefit
of making it almost trivial to translate analytical calculations into working numerical
code.
For simplicity, in this article we shall restrict our attention to collocation methods
where the continuous and discrete forms of the integro-differential equation have es-
sentially the same structure. It is important to recognize, however, that the method
can also be applied to Galerkin methods by applying the method directly to the
weak-form of the problem.
1. The Direct Matrix Method. There are two basic ideas underlying the
direct matrix method for calculating analytical Jacobians of discretized, integro-
differential equations. First, rather than writing the discretized, integro-differential
equations at each of the collocation points in terms of individual elements of the
solution vector, we write the entire system of equations as a single vector equation
expressed explicitly in terms of matrix-vector products and component-wise multi-
plication. Second, the analytical Jacobian for the discretized system of equations is
computed directly in matrix form by using simple differentiation rules that are remi-
niscent of those used to compute derivatives in single-variable calculus. In this section,
we develop both of these ideas in detail. Towards the end of the section, we comment
on the relationship between the direct matrix method and the Newton-Kantorovich
method [4] (also known as quasilinearization [24]).
1.1. Matrix-vector Representation of Discretized Equations. Writing
the discretized, nonlinear integro-differential equation explicitly in terms of basic lin-
ear algebra and component-wise algebraic operations is the initial step of the direct
matrix method. Because of the similarities in the structure between the discrete and
continuous forms of the equations, the procedure is very straightforward. First, con-
vert all differentiation and integration operators into their discrete analogues. Since
both of these operations are linear, they become multiplication of vectors representing
grid functions by differentiation and quadrature matrices, respectively:
du
(1.1) → D ∗ û
Z dx
(1.2) udx → Q ∗ û,

where the hat accent indicates a discretized field variable and D and Q are the differ-
entiation and quadrature matrices associated with the choice of computational grid.
Next, convert all point-wise algebraic operations and function evaluations in the
continuous equations to component-wise algebraic operations and function evaluations
in the discrete equations. Some examples of the conversion process include:
dv
(1.3) u → û .∗ (D ∗ v̂)
dx
DIRECT MATRIX METHOD FOR NONLIN. INTEGRO-DIFF. EQs 5

(1.4) sin(u) → sin(û)


(1.5) u2 → û.∧ 2
(1.6) exp(u) → exp(û).

In these examples, we have adopted the MATLAB convention of using .op to represent
component-wise application of the op operation. Also, note that we have abused
notation for component-wise function evaluations – f (û) represents the vector

(1.7) (f (û1 ), f (û2 ), . . . , f (ûN ))

not an arbitrary vector function of the entire solution vector û. We will continue to
use this notation for the remainder of our discussion.
It is worth mentioning that these procedures are not restricted to scalar field
equations or equations in one spatial variable. Vector equations may be handled by
treating the vector equation as a system of equations; vector operations may be ex-
pressed in component-wise form. Equations in multiple space dimensions may be
handled by using a natural ordering for the grid points and constructing differen-
tial/integral operators using Kronecker products [3]. For instance, the discretized
~ , can be written as
form of the curl of a vector field, U
 
Dy ∗ Uz − Dz ∗ Uy
(1.8)  Dz ∗ Ux − Dx ∗ Uz  ,
Dx ∗ Uy − Dy ∗ Ux

~ and Dx , Dy , and Dz are the differen-


where Ux , Uy , and Uz are the components of U
tiation matrices (constructed using Kronecker products) for partial derivatives in the
x-, y-, and z-directions, respectively.
1.2. Simple Differentiation Rules for Computing Exact Jacobians. Once
the continuous equations have been put in a discretized form that is expressed ex-
plicitly in terms of matrix-vector products and component-wise operations, the an-
alytical Jacobian for the discretized equations can be calculated by applying a few
simple matrix -based differentiation rules. Because the differentiation rules are ex-
pressed completely in matrix form (without any reference to individual elements in
the Jacobian matrix), they allow us to compute the Jacobian directly in matrix form.
In this section, we list these differentiation rules, which are essentially results from
multivariate and matrix calculus applied specifically to the structure of discretized
integro-differential equations.
1.2.1. Matrix-Vector Product Rule. The Jacobian of a matrix-vector prod-
uct (which corresponds to a linear operator acting on a function in the continuous
equations) is just the matrix itself:


(1.9) (Aû) = A.
∂ û
For example, the Jacobian of the discretized derivative of u, D ∗ û, is just D.
1.2.2. Diagonal Rule. The Jacobian of a component-wise function f of a grid
function û is a diagonal matrix with diagonal entries given by f ′ (û):

∂f (û)
(1.10) = diag [f ′ (û)] .
∂ û
6 KEVIN T. CHU

In essence, the diagonal rule is a way to use matrix notation to represent the fact that
the differential in the i-th component of f (û) only depends on the change in the i-th
component of û and is given by δf (ûi ) = f ′ (ûi )δûi , As an example, the Jacobian of
sin(û) is diag [cos(û)].
1.2.3. Chain Rules. The Jacobian of a matrix A times a component-wise func-
tion f (û) is A times the diagonal matrix with f ′ (û) on the diagonal:

(1.11) (A ∗ f (û)) = A ∗ diag [f ′ (û)]
∂ û
The Jacobian of a component-wise function f of a matrix A times the grid function
û is the diagonal matrix with f ′ (A ∗ û) on the diagonal times the A:

(1.12) f (A ∗ û) = diag [f ′ (û)] ∗ A
∂ û
These rules follow from the chain rule for vector fields from multivariate calcu-
lus [25].
1.2.4. Product Rule. To compute the Jacobian of a component-wise product
of functions of a grid function û, we use the product rule:
∂ ∂f ∂g
(1.13) (f (û) .∗ g(û)) = diag [g(û)] ∗ + diag [f (û)] ∗ .
∂ û ∂ û ∂ û
The derivation of the product rule is a straightforward application of the previous
three differentiation rules and the observation that the multiplication of two grid
functions û and v̂ can be rewritten as the product of a diagonal matrix with entries
from one grid function multiplying the vector representing the other grid function:

(1.14) û .∗ v̂ = diag (û) .∗ v̂ = diag (v̂) .∗ û.

1.3. Example Jacobian Calculations. As our first example, let us consider


the 1D Poisson equation:

d2 u
(1.15) + ρ = 0.
dx2
To put this in discretized form, we need only replace the continuous second derivative
operator by a discrete analogue:

(1.16) D2 û + ρ̂ = 0.

Here, we have chosen to apply the discrete single derivative operator twice. Via a
direct application of the matrix-vector product rule (1.9), the Jacobian of the left-
hand side of this equation is easily found to be D2 . Since this is a linear equation,
there would not normally be a need to compute the Jacobian of the left hand side
of this equation. Moreover, the Jacobian for this example is very easy to calculate
using alternative means (or even by inspection). We merely present it to illustrate
the direct matrix method on a standard model problem.
As a less trivial, let us calculate the Jacobian for the discretized form of the
nonlinear function
du
(1.17) f (u) = e2u .
dx
DIRECT MATRIX METHOD FOR NONLIN. INTEGRO-DIFF. EQs 7

Converting this function to discrete form, we obtain


(1.18) f (û) = (e.∧ (2û)) .∗ (Dû).
Using the product rule (1.13), we find that the the Jacobian is given by
∂ ∂(Dû)
(1.19) J = diag[Dû] ∗ (e.∧ (2û)) + diag [e.∧ (2û)] ∗ .
∂ û ∂ û
Then applying the matrix-vector product rule (1.9) and the diagonal rule (1.10), we
find that
(1.20) J = 2diag[Dû] ∗ diag [e.∧ (2û)] + diag [e.∧ (2û)] ∗ D,
which can be simplified to
(1.21) J = 2diag [(Dû) .∗ (e.∧ (2û))] + diag [e.∧ (2û)] ∗ D
by observing that
(1.22) diag [û .∗ v̂] = diag [û] ∗ diag [v̂] .
As a final example, let us calculate the Jacobian for the nonlinear algebraic equa-
tions that arise when solving the one-dimensional version of (0.1) – (0.3) using a
simple backwards Euler discretization in time. Using the direct matrix approach for
(n+1) (n+1)
the spatial discretization, the nonlinear algebraic equations for ĉ+ and ĉ− that
need to be solved at each time step are:
  
(n+1) (n+1) (n+1) (n)
(1.23) ĉ+ − ∆t D2 ∗ ĉ+ + D ∗ ĉ+ .∗ (D ∗ φ̂) − ĉ+ = 0
  
(n+1) (n+1) (n+1) (n)
(1.24) ĉ− − ∆t D2 ∗ ĉ− − D ∗ ĉ− .∗ (D ∗ φ̂) − ĉ− = 0
 
(n+1) (n+1)
(1.25) ǫD2 ∗ φ̂ + ĉ+ − ĉ− =0

(n)
where ĉ± are the concentrations at the current time step and ∆t is the time step size.
It is important to mention that several of the rows in (1.25) will typically be replaced
to impose the discretized form of the boundary conditions for φ. For illustrative
purposes, let us suppose that we have simple Dirichlet boundary conditions for φ. In
this situation, (1.25) is only imposed at interior grid points [3].
Using the simple differentiation rules from the previous section, the Jacobian of
(n+1)
(1.23) with respect to ĉ+ is
!
2
h i h
(n+1)
i ∂ φ̂
(1.26) I − ∆t D + D ∗ diag D ∗ φ̂ + D ∗ diag ĉ+ ∗ D ∗ (n+1) ,
∂ĉ+
∂ φ̂ (n+1)
where I is the identity matrix and (n+1) is the Jacobian of φ̂ with respect to ĉ+ .
∂ĉ+
∂ φ̂
To eliminate (n+1) from this expression, we simply apply the differentiation rules to
∂ĉ+
(1.25) with two rows eliminated for the boundary conditions and solve for the interior
portion of ∂ φ̂(n+1) :
∂ĉ+
!
∂ φ̂ 1 −1
(1.27) (n+1)
=− D2 int ,
∂ĉ+ ǫ
int
8 KEVIN T. CHU

where D2 int is the submatrix of D2 that remains when all of the columns and rows


corresponding to boundary grid points have been removed. Since the boundary values
(n+1)
of φ̂ are fixed and the values of ĉ+ at the boundaries do not affect the potential
∂ φ̂
in the interior, the full Jacobian (n+1) is given by
∂ĉ+

 
0 ··· 0
∂ φ̂  .. −1 .. 
(1.28) (n+1)
= . − 1ǫ D2 . ,
∂ĉ+ int
0 ··· 0

where we have assumed that the first and last grid points correspond to boundary
points. It is important to recognize that the form for ∂ φ̂(n+1) in (1.28) is specific to
∂ĉ+
problems with Dirichlet boundary conditions for φ. For other boundary conditions,
the inversion of the equation for ∂ φ̂(n+1) will lead to different forms for the Jacobian.
∂ĉ+
The Jacobian for (1.23) can now be explicitly computed by substituting (1.28) into
(1.26). The similar expression for the Jacobian of (1.24) is obtained using an analogous
procedure. Using the direct matrix approach, we have reduced the calculation of the
Jacobian to O(N 3 ) compared to the O(N 4 ) cost for computing a numerical Jacobian
for high-order spatial discretizations. It is worth pointing out that in this example, the
Jacobian for the concentrations does not depend explicitly on φ because the Poisson
equation is linear. As a result, there is no need to solve for φ in order to compute
the Jacobians for (1.23) and (1.24). For general problems, the Jacobian may depend
on the auxiliary variable, so it might be necessary to solve the constraint equation.
However, even in this case, the direct matrix approach still dramatically reduces the
cost of computing the Jacobian compared to using finite differences.
2. Relationship to the Newton-Kantorovich Method. The direct matrix
method for computing the Jacobian of discretized integro-differential equations is
closely related to the calculation of the Fréchet derivative2 used in the Newton-
Kantorovich method [4] (also known as quasilinearization [24]). The basic idea behind
solving nonlinear integro-differential equations using the Newton-Kantorovich method
is to carry out Newton’s method in function space. For each Newton iteration, we com-
pute the Fréchet derivative of the integro-differential equation in function space and
numerically solve the resulting linear integro-differential equation for the correction
to the current iterate of the solution. Essentially, the Newton-Kantorovich method
reverses the order of (1) discretization of the continuous problem and (2) Newton
iteration. Because the equations to be solved during each Newton iteration is linear,
there is no need to compute a Jacobian of the discretized equations.
An important feature of the Newton-Kantorovich method is that the numerical
discretization used to solve the linearized equation during each Newton iteration can,
in principle, be completely independent of the discretization used to compute the
residual of the nonlinear integro-differential equation. This freedom can affect the
convergence rate of the method depending on the degree to which the discretized
form of the linearized problem approximates the Jacobian of the discretized residual
equation.

2 Recall that the Fréchet derivative for nonlinear functionals is the generalization of the Jacobian

for nonlinear functions over finite-dimensional spaces [4, 26, 27]. For intuition, Ortega and Rheinboldt
provide a nice discussion of Fréchet derivatives in the context of finite-dimensional spaces [28].
DIRECT MATRIX METHOD FOR NONLIN. INTEGRO-DIFF. EQs 9

Because the direct matrix method begins with a discrete equation possessing
the same mathematical structure as the continuous residual equation, it produces
a Jacobian that is a discrete analogue of the Fréchet derivative for the continuous
integro-differential equation. Unlike the Newton-Kantorovich method, however, the
direct matrix method produces a unique Jacobian given a particular choice of dis-
cretization for the residual of the nonlinear integro-differential equation. The freedom
to independently choose the numerical discretizations for the residual equation and
the Fréchet derivative is not present in the direct matrix method. As a result, given
a numerical discretization for the residual equation, the direct matrix method can be
viewed as a way to generate the optimal discretization for the linearized equation that
arises during each Newton iteration of the Newton-Kantorovich method.
3. Applications.
3.1. Nanostructure Shape. The evolution and relaxation of surface structures
are important processes that are of current interest to the material science community.
Under certain conditions, the profile of an axisymmetric nanostructure can be shown
to satisfy the following nonlinear ordinary differential equation3 [29, 30]

d3 f p
(3.1) − f +1=0
dx3
on the domain (0, ∞) subject to the boundary conditions

df
(3.2) f (0) = 0 , (0) = α , lim f → 1.
dx x→∞

Here x is the distance from the top facet of the nanostructure, f represents the
slope of the nanostructure and α is an O(1) parameter related to the curvature of the
nanostructure at the edge of the top facet.
To solve this boundary value problem, it is convenient and efficient to use a pseu-
dospectral method based on the rational Chebyshev functions4 [4]. The computational
grid for this method consists of the the points:
 
1 + yi
(3.3) xi = L
1 − yi

where yi are the Chebyshev grid points in [−1, 1] and L is a scaling factor that controls
how much of the semi-infinite domain is “covered” by grid points5 . The differentiation
matrix corresponding to this computational grid is

(1 − yi )2
 
(3.4) D = diag ∗ Dcheb ,
2L

where Dcheb is the differentiation matrix for the Chebyshev grid [3, 4, 5].
3 Equation (3.1) is derived by seeking a similarity to the fourth-order partial differential equations

governing nanostructure evolution in time [29].


4 The rational Chebyshev functions for semi-infinite domains are just the Chebyshev polynomials,

Tn (y), under the change of variables x = L(1 + y)/(1 − y), where L is a scaling factor. Methods
based on rational Chebyshev functions have the advantage that they allow the solution to decay
algebraically or asymptote to a constant at infinity [4].
5 Typically, L is chosen to be on the order of the scale over which the variations for the problem

occur [4].
10 KEVIN T. CHU

Having selected the computational grid and defined the corresponding differenti-
ation matrix, it is straightforward to write down a numerical discretization of (3.1) in
matrix-vector form:
q
(3.5) D3 ∗ fˆ − fˆ + 1 = 0.

To impose the Dirichlet boundary conditions in (3.2), we merely treat the values of
the solution at xi = 0 and xi = ∞ as known values by removing the components
of (3.5) corresponding these points and explicitly accounting for the contributions of
fˆ at these grid points in the remaining discrete equations. The Neumann boundary
condition may be handled by replacing one other equation in (3.5) with a discrete
equation enforcing the boundary condition:

(3.6) D0 ∗ fˆ − α = 0,

where D0 is the row of the differentiation matrix corresponding to xi = 0. Because


there are fewer critical features of the solution near infinity, we chose to replace the
component of (3.5) corresponding to the largest finite grid point.
Written in this form, we can easily compute the Jacobian for the left-hand side of
the discretized equations. For the components of the residual where (3.5) are imposed
(i.e., the interior grid points), application of the differentiation rules from Section 1
yields
 
1
(3.7) Jint = D3 − diag  q  .
2 fˆ

The row of the Jacobian associated with the Neumann boundary condition is obtained
by applying the differentiation rules to (3.6)

(3.8) Jbdry = D0 .

It is important to realize that as a result of the way we have chosen to impose the
Dirichlet boundary conditions, the columns of the Jacobian in (3.7) and (3.8) corre-
sponding to the grid points xi = 0 and xi = ∞ must be removed before computing
the correction to the current Newton iterate.
With the discretized residual equation (3.5) – (3.6) and its Jacobian (3.7) – (3.8),
we now have all of the components required for Newton’s method. Because both the
discretized equation and the Jacobian are written in matrix-vector form, a MATLAB
code solving the equations is quite short and requires only a few Newton iterations to
converge to the solution (see Appendix A). Figure 3.1 shows the numerical solution
of (3.1) and (3.2) computed using 200 grid points and a scaling factor of 5 with α
set to 1. As we can see in Figure 3.2, we are able to obtain subgeometric (but better
than algebraic) convergence (at least to the precision of our computation) using the
rational Chebyshev grid [4]. The convergence rate shown in Figure 3.2 delivers an
important message: we can obtain very accurate solutions with far fewer than 200
grid points if we are willing to give up accuracy to full machine precision.
3.2. Electrochemical Thin-Films. Analysis of micro-electrochemical systems
leads to an interesting example of a nonlinear integro-differential equation. For steady-
state electrochemical thin-films made up of a dilute solution of symmetric binary
DIRECT MATRIX METHOD FOR NONLIN. INTEGRO-DIFF. EQs 11

1.5

0.5

0
0 5 10 15 20 25
x

Fig. 3.1. Solution of nanostructure evolution equations (3.1) and (3.2) computed using 200
grid points and a scaling factor of 5 with α set to 1.

0 0
10 10

|an| |an|
−5 −5
10 10

−10 −10
10 10

0 1 2
10 10 10 0 50 100 150 200 250
n n

Fig. 3.2. Log-log (left) and semilog (right) plots of the absolute value of the spectral co-
efficients, an , for the numerical solution of (3.1) and (3.2) as a function of the basis function
degree. The two plots demonstrate that, for the nanostructure shape equation, the pseudospectral
discretization method based on the rational Chebyshev basis functions converges subgeometrically
(log-log plot is concave down and semilog plot is concave up) with respect to the number of grid
points used in the numerical solution (up to the numerical precision of the computer). Note that
the spectral coefficients were calculated from a numerical solution of (3.1) and (3.2) generated
using 250 grid points to make the roundoff plateau more apparent.

electrolyte with faradaic reactions at the surfaces of the thin-film [31, 32], the electric
field, E, satisfies the second-order differential equation6
 2 
2 d E 1 3 1 j
(3.9) ǫ − E − (c0 + j(x + 1)) E − = 0
dx2 2 4 4

on the domain (−1, 1) subject to boundary conditions that represent the kinetics of
electrode reactions

(3.10) − kc (c(1) + ρ(1)) + jr − j = 0


(3.11) kc (c(−1) + ρ(−1)) − jr − j = 0,

6 To simplify the discussion, equation (3.9) is a slightly modified form of the master equation

in [31, 32] derived by making the substitutions x → (x + 1)/2 and E → 2E.


12 KEVIN T. CHU

where c is the average salt concentration, ρ is the charge density, j is the current den-
sity flowing through the thin-film, ǫ is a parameter related to the dielectric constant,
kc and jr are reaction rate constants, and c0 is the following expression
 Z 1 
2 2
(3.12) c0 = (1 − j) + ǫ 2E(1) − 2E(−1) − E dx .
−1

The average salt concentration and charge density are related to the electric field via
the equations

dE
(3.13) c(x) = c0 + j(x + 1) + 2ǫ2 E 2 , ρ(x) = 4ǫ2 .
dx

While this set of equations may seem daunting, we can solve it via Newton’s
method using a systematic application of the direct matrix method. For this problem,
we shall discretize the problem using a pseudospectral method based on the Chebyshev
grid on the interval [−1, 1]. The differentiation matrix, D, for this computational
grid is just the standard differentiation matrix for the Chebyshev grid [3, 4, 5]. For
numerical integration, we can use the Clenshaw-Curtis quadrature weights [3], which
we shall denote by the row vector w. The quadrature weights can be used to construct
an quadrature matrix, Q, which is the analogue of the differentiation matrix:
 
w
 w 
(3.14) Q=  ··· .

When a grid function f is multiplied by Q, the result is a vector where all entries are
equal to the integral of f .
With these discrete operators, we can put (3.9) into matrix-vector form:
 
1 1  j
(3.15) ǫ2 D2 ∗ Ê − Ê.∧ 3 − Ĉ0 + j(x + 1) . ∗ Ê − = 0
2 4 4

with
 
(3.16) Ĉ0 = (1 − j) + ǫ2 2Ê1 − 2ÊN − Q ∗ (Ê.∧ 2) ,

where we have chosen to order the indices so that x1 = 1 and xN = −1 (this follows
the convention used in [3] and in the code in Appendix B). The boundary conditions
are imposed by replacing the discrete equations corresponding to x1 and xN with
  
(3.17) − kc ĉ0 + 2j + ǫ2 2Ê12 + 4D1 ∗ Ê + jr − j = 0
  
(3.18) kc ĉ0 + ǫ2 2ÊN2
+ 4DN ∗ Ê − jr − j = 0,

where D1 and DN are the rows of the differentiation matrix corresponding to x1 and
xN , respectively, and ĉ0 is a single component of Ĉ0
 
(3.19) ĉ0 = (1 − j) + ǫ2 2Ê1 − 2ÊN − w ∗ (Ê.∧ 2) .
DIRECT MATRIX METHOD FOR NONLIN. INTEGRO-DIFF. EQs 13

The Jacobians for the left-hand side of these discrete equations are now easily
computed. Applying the differentiation rules from Section 1, the Jacobian for the
interior grid points is
 
3 1 1 ∂ Ĉ0
(3.20)Jint = ǫ2 D2 − diag[Ê.∧ 2] − diag[Ĉ0 + j(x + 1)] − diag[Ê] ∗
2 4 4 ∂ Ê
with
  
2 0 · · · 0 −2
∂ Ĉ0
(3.21) = ǫ2  ... ... .. .. ..  − 2Q ∗ diag[Ê]

. . .  
∂ Ê
2 0 · · · 0 −2

The Jacobian for the discretized boundary conditions are similarly calculated:
 
∂ĉ0
(3.22) J1 = −kc + 4ǫ2 [E1 0 . . . 0] + 4ǫ2 D1
∂ Ê
 
∂ĉ0
(3.23) JN = kc + 4ǫ2 [0 . . . 0 EN ] + 4ǫ2 DN ,
∂ Ê
where
∂ĉ0  
(3.24) = ǫ2 [2 0 . . . 0 − 2] − 2w ∗ diag[Ê]
∂ Ê
Now that we have explicitly computed all of the components for Newton’s method,
it is straightforward to write a program to solve the nonlinear integro-differential
equations for electrochemical thin-films. As before, the MATLAB code for solving
is relatively short and runs quickly (see Appendix B). One special issue that arises
for this problem is that continuation methods [4] are required to obtain good initial
iterates for the Newton iteration at high current densities. Figure 3.3 shows the
numerical solution of (3.9) – (3.11) computed using 200 grid points with ǫ = 0.01,
kc = 10, and jr = 10 for various values of j. As expected, we observe geometric
convergence with respect to the number of grid points (see Figure 3.4). Notice that at
higher current densities, we see slower convergence rates due to the presence of greater
structure in the solution. As in the nanostructure example, the fast convergence
(geometric in this example) of the pseudospectral method implies that we can obtain
accurate solutions even if we use far fewer than 200 grid points.
While quite satisfactory, the convergence rate for the numerical discretization
(3.15) – (3.19) as a function of the number of grid points is limited by the need to
resolve the boundary layers. By using a mapping of the computational domain that
allows us to place a few grid points within the boundary layers, we can obtain a faster
convergence rate. For example, by using the variable transformation:
1 β
(3.25) x= tanh (atanh(β)y) , E(x) = cosh2 (atanh(β)y) E(y),
β atanhβ
where β is an adjustable parameter less than 1, we can significantly reduce the number
of grid points required obtain a solution accurate to machine precision (see Figure 3.4).
It is interesting to note that the optimal value for β depends on the current density j.
For j = 0.5 and j = 1.0, a β value of 0.9 yields near optimal results. For j = 1.5, how-
ever, the fastest convergence is obtained near β = 0.75. As is typical, the transformed
14 KEVIN T. CHU

−20

−40
E

−60

−80

−100
−1 −0.5 0 0.5 1
x

Fig. 3.3. Solution of electrochemical thin-film equations (3.9) – (3.11) computed using 200
grid points with ǫ = 0.01, kc = 10, and jr = 10 for j = 1.5 (solid), j = 1.0 (dash), and j = 0.5
(dot-dash).

0 0
10 10

|a | −5 |a | −5
n 10 n 10

−10 −10
10 10

−15 −15
10 10
0 50 100 150 200 250 0 50 100 150 200 250
x x

Fig. 3.4. Plots of the absolute value of the spectral coefficients, an , for the numerical solution
of the electrochemical thin-film equations with j = 1.5 (solid), j = 1.0 (dash), and j = 0.5 (dot-
dash) as a function of the basis function degree when (3.9) – (3.11) are solved directly (left) and
using the variable transformation (3.25) to place more grid points in the boundary layers (right).
Although the convergence rate as a function of number of grid points is geometric in all cases,
the variable transformation significantly reduces the number of grid points required obtain the best
solution possible given the precision of the computation. Note that the spectral coefficients were
calculated from a numerical solution generated using 250 grid points to make the roundoff plateau
more apparent.

electrochemical thin-film equations are bit more complicated to deal with than the
original equations. However, the direct matrix method makes it straightforward to
discretize the transformed equations and compute the exact Jacobian for the resulting
nonlinear algebraic equations (see Appendix C).
4. Conclusions. In this article, we have presented the direct matrix method for
calculating analytical Jacobians for discretized, nonlinear integro-differential equa-
tions. Because this method is based on simple matrix-based differentiation rules, it
is less tedious and less error prone than other approaches for computing analytical
Jacobians of the discretized equations. Furthermore, because it yields the Jacobian
in matrix form, it is very easy to use languages that support vectorized computation
to implement numerical methods that require the Jacobian.
One interesting possibility that the direct matrix method presents is development
DIRECT MATRIX METHOD FOR NONLIN. INTEGRO-DIFF. EQs 15

of high-level automatic differentiation tool for discretized nonlinear integro-differential


equations. In contrast to traditional automatic differentiation methods [33, 34] which
operate at the level of individual scalar operations, automatic differentiation methods
based on the direct matrix method would operate on the discrete differential operators
associated with the continuous differential equation. Such an automatic differentiation
tool could be useful for completely eliminating the need for a researcher to compute
the Jacobian of discretized nonlinear integro-differential equations.
Acknowledgments. The author gratefully acknowledges the support of the De-
partment of Energy through the Computational Science Graduate Fellowship (CSGF)
Program provided under grant number DE-FG02-97ER25308. The author thanks
B. Kim for many helpful discussions that led to the development of the direct ma-
trix method, P. Fok for providing and explaining the nanostructure example, and
J. P. Boyd for offering many helpful suggestions.
Appendix A. MATLAB Code for Nanostructure Example. This code
relies on cheb.m by N. Trefethen [3].

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
alpha = 1;
f_inf = 1; % f at x = infinity
N = 200;
L = 50;
res_tol = 1e-8;
max_iters = 20;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% compute differentiation matrix and grid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% compute Chebyshev differentiation matrix on interval [-1,1]
[D_y,y] = cheb(N);
one_minus_y = diag(1-y);
warning off MATLAB:divideByZero % disable warning message
D = 0.5/L*(one_minus_y^2)*D_y; x = L*(1+y)./(1-y);
warning on MATLAB:divideByZero % re-enable warning message
x_int = x(2:end-1); % extract interior grid points

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% construct discrete operators
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
D3 = D^3;
% contributions to D^3 from interior grid points and grid
% point at infinity
D3_int = D3(2:end-1,2:end-1); D3_inf = D3(2:end-1,1);
% contribution to Neuman BC from interior grid points and
% grid point at infinity
BC_f_prime_int = D(end,2:end-1); BC_f_prime_inf = D(end,1);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16 KEVIN T. CHU

% initialize Newton iteration


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f_int = f_inf*atan(x_int); % initial iterate
count = 0;
res = D3_int*f_int + D3_inf*f_inf - sqrt(f_int) + 1;
res(1) = BC_f_prime_int*f_int + BC_f_prime_inf*f_inf - alpha;
res_norm = norm(res,inf);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Newton iteration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
while ( res_norm > res_tol & count < max_iters)

% compute Jacobian
J = D3_int - 0.5*diag(1./sqrt(f_int));
J(1,:) = BC_f_prime_int; % Neumann boundary condition

% compute delta_f and update solution


delta_f = -J\res; f_int = f_int + delta_f;

% update residual
res = D3_int*f_int + D3_inf*f_inf - sqrt(f_int) + 1;
res(1) = BC_f_prime_int*f_int + BC_f_prime_inf*f_inf - alpha;

% update loop variables


res_norm = norm(res,inf)
count = count + 1

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot solution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1); clf;
plot(x,[f_inf; f_int; 0],’k-’);
axis([0 25 0 2.5]);
xlabel(’x’); ylabel(’f’,’Rotation’,0);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot spectral coefficients
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f = [f_inf; f_int; 0];
coefs = abs(fft([f; flipud(f(2:end-1))]));

figure(2); clf;
loglog(coefs(1:N),’ko’);
axis([1 N 1e-12 1000]);
xlabel(’n’); ylabel(’|a_n|’,’Rotation’,0);
DIRECT MATRIX METHOD FOR NONLIN. INTEGRO-DIFF. EQs 17

figure(3); clf;
semilogy(coefs(1:N),’ko’);
axis([0 N 1e-12 1000]);
xlabel(’n’); ylabel(’|a_n|’,’Rotation’,0);

Appendix B. MATLAB Code for Electrochemical Thin-Film Example.


This code relies on cheb.m and clencurt.m by N. Trefethen [3].

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
j = 1.5;
epsilon = 0.01;
k_c = 10;
j_r = 10;
N = 200;
res_tol = 1e-8;
max_iters = 20;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% compute grid, differentiation matrix, and quadrature matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[D,x] = cheb(N-1); % Chebyshev differentiation matrix
[x,w] = clencurt(N-1); % Clenshaw-Curtis quadrature weights
Q = kron(ones(N,1),w); % quadrature matrix
L = D*D; % Laplacian operator

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set up continuation in j
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
total_count = 0; % total number of iterations required
j_start = 0.5;
dj = 0.1;
j_cur = j_start;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% generate initial iterate for Newton iteration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
eps23 = epsilon^(2/3);
c0 = 1-j_cur;
c = c0 + j_cur*(x+1);
E = -2*j_cur./(j_cur*(x+1)+c0);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Newton iteration with simple continuation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
while ( j_cur < j + 1e-5 ) % make sure that j is reached

% display j_cur and total count


j_cur = j_cur
18 KEVIN T. CHU

total_count = total_count

% initialize Newton iteration


count = 0; % iteration count for single Newton iteration
C0 = 1-j_cur + epsilon^2*(2*E(1)-2*E(N)-Q*(E.^2));
c0 = C0(1);
res = epsilon^2*(L*E-0.5*E.^3) ...
- 0.25*(C0+j_cur*(x+1)).*E - 0.25*j_cur;
res(1) = -k_c*(c0+2*j_cur+epsilon^2*(2*E(1)^2+4*D(1,:)*E)) ...
+ j_r - j_cur;
res(N) = k_c*(c0+epsilon^2*(2*E(N)^2+4*D(N,:)*E)) ...
- j_r - j_cur;
res_norm = norm(res,inf);

while ( (res_norm > res_tol) & (count < max_iters) )

% construct Jacobian for interior grid points


dC0_dE = -2*epsilon^2*Q*diag(E);
dC0_dE(:,1) = dC0_dE(:,1) + 2*epsilon^2*ones(N,1);
dC0_dE(:,N) = dC0_dE(:,N) - 2*epsilon^2*ones(N,1);
J = epsilon^2*(L-1.5*diag(E.*E)) - 0.25*diag(C0+j_cur*(x+1)) ...
- 0.25*diag(E)*dC0_dE;

% construct Jacobian for boundary conditions


dc0_dE = -2*epsilon^2*w*diag(E);
dc0_dE(1) = dc0_dE(1) + 2*epsilon^2;
dc0_dE(N) = dc0_dE(N) - 2*epsilon^2;
J(1,:) = -k_c*(dc0_dE + 4*epsilon^2*D(1,:));
J(1,1) = J(1,1) - 4*k_c*epsilon^2*E(1);
J(N,:) = k_c*(dc0_dE + 4*epsilon^2*D(N,:));
J(N,N) = J(N,N) + 4*k_c*epsilon^2*E(N);

% compute delta_E and update solution


delta_E = -J\res; E = E + delta_E;

% update residual
C0 = 1-j_cur + epsilon^2*(2*E(1)-2*E(N)-Q*(E.^2));
c0 = C0(1);
res = epsilon^2*(L*E-0.5*E.^3) ...
- 0.25*(C0+j_cur*(x+1)).*E - 0.25*j_cur;
res(1) = -k_c*(c0+2*j_cur+epsilon^2*(2*E(1)^2+4*D(1,:)*E)) ...
+ j_r - j_cur;
res(N) = k_c*(c0+epsilon^2*(2*E(N)^2+4*D(N,:)*E)) ...
- j_r - j_cur;

% update loop variables


res_norm = norm(res,inf)
count = count + 1
DIRECT MATRIX METHOD FOR NONLIN. INTEGRO-DIFF. EQs 19

end % Newton iteration loop

% update continuation variables


j_cur = j_cur + dj;
total_count = total_count + count;

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot solution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1); clf;
plot(x,E,’k-’);
axis([-1 1 -100 0]);
xlabel(’x’); ylabel(’E’,’Rotation’,0);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot spectral coefficients
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
coefs = abs(fft([E; flipud(E(2:end-1))]));
figure(2); clf;
semilogy(coefs(1:N),’ko’);
axis([0 N 1e-15 1e4]);
xlabel(’n’); ylabel(’|a_n|’,’Rotation’,0,’Position’,[-32 5e-6]);

Appendix C. MATLAB Code for Electrochemical Thin-Film Example


with Variable Transformation. This code relies on cheb.m and clencurt.m by
N. Trefethen [3].

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
j = 1.5;
epsilon = 0.01;
k_c = 10;
j_r = 10;
N = 200;
beta = 0.75;
alpha = atanh(beta);
res_tol = 1e-8;
max_iters = 20;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% compute grid, differentiation matrix, and quadrature weights
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[D,y] = cheb(N-1); % Chebyshev differentiation matrix
[y,w] = clencurt(N-1); % Clenshaw-Curtis quadrature weights
Q = kron(ones(N,1),w); % quadrature matrix

x = tanh(alpha*y)/beta; % mapped grid points


20 KEVIN T. CHU

gamma = beta/alpha*cosh(alpha*y).^2; % derivative transform factor


L = diag(gamma)*D*diag(gamma)*D; % transformed Laplacian operator

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set up continuation in j
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
total_count = 0; % total number of iterations required
j_start = 0.5;
dj = 0.1;
j_cur = j_start;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% generate initial iterate for Newton iteration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
eps23 = epsilon^(2/3);
c0 = 1-j_cur;
c = c0 + j_cur*(x+1);
E = -2*j_cur./(j_cur*(x+1)+c0);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Newton iteration with simple continuation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
while ( j_cur < j + 1e-5 ) % make sure that j is reached

% display j_cur and total count


j_cur = j_cur
total_count = total_count

% initialize Newton iteration


count = 0; % iteration count for single Newton iteration
C0 = 1-j_cur ...
+ epsilon^2*(2*gamma(1)*E(1)-2*gamma(N)*E(N) ...
-Q*(gamma.*(E.^2)));
c0 = C0(1);
res = epsilon^2*(L*(gamma.*E)-0.5*(gamma.^3).*(E.^3)) ...
- 0.25*(C0+j_cur*(x+1)).*gamma.*E - 0.25*j_cur;
res(1) = -k_c*(c0+2*j_cur ...
+epsilon^2*(2*gamma(1)^2*E(1)^2 ...
+4*gamma(1)*D(1,:)*(gamma.*E))) ...
+ j_r - j_cur;
res(N) = k_c*(c0+epsilon^2*(2*gamma(N)^2*E(N)^2 ...
+4*gamma(N)*D(N,:)*(gamma.*E))) ...
- j_r - j_cur;
res_norm = norm(res,inf);

while ( (res_norm > res_tol) & (count < max_iters) )

% construct Jacobian for interior grid points


DIRECT MATRIX METHOD FOR NONLIN. INTEGRO-DIFF. EQs 21

dC0_dE = -2*epsilon^2*Q*diag(gamma.*E);
dC0_dE(:,1) = dC0_dE(:,1) + 2*epsilon^2*gamma(1)*ones(N,1);
dC0_dE(:,N) = dC0_dE(:,N) - 2*epsilon^2*gamma(N)*ones(N,1);
J = epsilon^2*(L*diag(gamma)-1.5*diag((gamma.^3).*(E.^2))) ...
- 0.25*diag(gamma.*(C0+j_cur*(x+1))) ...
- 0.25*diag(gamma.*E)*dC0_dE;

% construct Jacobian for boundary conditions


dc0_dE = -2*epsilon^2*w*diag(gamma.*E);
dc0_dE(1) = dc0_dE(1) + 2*epsilon^2*gamma(1);
dc0_dE(N) = dc0_dE(N) - 2*epsilon^2*gamma(N);
J(1,:) = -k_c*(dc0_dE + 4*epsilon^2*gamma(1)*D(1,:)*diag(gamma));
J(1,1) = J(1,1) - 4*k_c*epsilon^2*gamma(1)^2*E(1);
J(N,:) = k_c*(dc0_dE + 4*epsilon^2*gamma(N)*D(N,:)*diag(gamma));
J(N,N) = J(N,N) + 4*k_c*epsilon^2*gamma(N)^2*E(N);

% compute delta_E and update solution


delta_E = -J\res; E = E + delta_E;

% update residual
C0 = 1-j_cur ...
+ epsilon^2*(2*gamma(1)*E(1)-2*gamma(N)*E(N) ...
-Q*(gamma.*(E.^2)));
c0 = C0(1);
res = epsilon^2*(L*(gamma.*E)-0.5*(gamma.^3).*(E.^3)) ...
- 0.25*(C0+j_cur*(x+1)).*gamma.*E - 0.25*j_cur;
res(1) = -k_c*(c0+2*j_cur ...
+epsilon^2*(2*gamma(1)^2*E(1)^2 ...
+4*gamma(1)*D(1,:)*(gamma.*E))) ...
+ j_r - j_cur;
res(N) = k_c*(c0+epsilon^2*(2*gamma(N)^2*E(N)^2 ...
+4*gamma(N)*D(N,:)*(gamma.*E))) ...
- j_r - j_cur;

% update loop variables


res_norm = norm(res,inf)
count = count + 1

end % Newton iteration loop

% update continuation variables


j_cur = j_cur + dj;
total_count = total_count + count;

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot solution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 KEVIN T. CHU

figure(1); clf;
plot(x,E.*gamma,’k-’);
axis([-1 1 -100 0]);
xlabel(’x’); ylabel(’E’,’Rotation’,0);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot spectral coefficients
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
coefs = abs(fft([E; flipud(E(2:end-1))]));
figure(2); clf;
semilogy(coefs(1:N),’ko’);
axis([0 N 1e-15 1e4]);
xlabel(’n’); ylabel(’|a_n|’,’Rotation’,0,’Position’,[-25 5e-6]);

REFERENCES

[1] C. T. Kelley. Solving Nonlinear Equations with Newton’s Method. SIAM, Philadelphia, PA,
2003.
[2] C. T. Kelley. Iterative Methods for Solving Linear and Nonlinear Equations. SIAM, Philadel-
phia, PA, 1995.
[3] L. N. Trefethen. Spectral Methods in MATLAB. SIAM, Philadelphia, PA, 2000.
[4] J. P. Boyd. Chebyshev and Fourier Spectral Methods. Dover Publications, Inc., Mineola, NY,
2nd edition, 2001.
[5] B. Fornberg. A Practical Guide to Pseudospectral Methods. Cambridge University Press, New
York, NY, 1998.
[6] G. Strang and G. J. Fix. An Analysis of the Finite Element Method. Wellesley-Cambridge
Press, Wellesley, MA, 1988.
[7] T. J. R. Hughes. The Finite Element Method. Dover Publications, Inc., Mineola, NY, 2000.
[8] D. Gottlieb and S. A. Orzag. Numerical Analysis of Spectral Methods : Theory and Applica-
tions. SIAM, Philadelphia, PA, 1977.
[9] T. F. Coleman and J. J. Moré. Estimation of sparse jacobian matrices and graph coloring
problems. SIAM J. Numer. Anal., 20:187–209, 1983.
[10] A. R. Curtis, M. J. D. Powell, and J. K. Reid. On the estimations of sparse jacobian matrices.
J. Inst. Math. Appl., 13:117–119, 1974.
[11] I. Rubinstein. Electro-Diffusion of Ions. SIAM Studies in Applied Mathematics, SIAM,
Philadelphia, PA, 1990.
[12] J. Newman. Electrochemical Systems. Prentice-Hall, Inc., Englewood Cliffs, NJ, second edition,
1991.
[13] J. D. Jackson. Classical Electrodynamics. John Wiley & Sons, Inc., 1998.
[14] J. W. Demmel. Applied Numerical Linear Algebra. SIAM, Philadelphia, PA, 1997.
[15] L. N. Trefethen and D. Bau. Numerical Linear Algebra. SIAM, Philadelphia, PA, 1997.
[16] W. Chen. Jacobian matrix: a bridge between linear and nonlinear polynomial-only problems.
1999.
[17] W. Chen, C. Shu, W. He, and T. Zhong. The application of special matrix product to differential
quadrature solution of geometrically nonlinear bending of orthotropic rectangular plates.
Computers & Structures, 74:65–76, 2000.
[18] K. T. Chu. Asymptotic Analysis of Extreme Electrochemical Transport. PhD thesis, Mas-
sachusetts Institute of Technology, Department of Mathematics, 2005.
[19] W. Chen and T. Zhong. The study on the nonlinear computations of the dq and dc methods.
Numerical Methods for Partial Differential Equations, 13:57–75, 1997.
[20] W. Chen, T. Zhong, and S. P. Liang. On the dq analysis of geometrically non-linear vibration
of immovably simply-supported beams. J. of Sound & Vibration, 206:745–748, 1997.
[21] W. Chen, T. Zhong, and Y. Yu. Applying special matrix product to nonlinear numerical
computations. J. Appl. Comp. Math., 12:51–58, 1998.
[22] W. Chen. Relationship theorem between nonlinear polynomial equation and the corresponding
jacobian matrix. Int. J. of Nonlinear Sciences and Numerical Simulation, 1:5–14, 2000.
[23] R. A. Horn and C. R. Johnson. Topics in matrix analysis. Cambridge University Press, 1991.
[24] P. Deuflhard. Newton Methods for Nonlinear Problems. Springer, Berlin, Germany, 2004.
DIRECT MATRIX METHOD FOR NONLIN. INTEGRO-DIFF. EQs 23

[25] T. M. Apostol. Calculus (Volume II). John Wiley & Sons, Inc., 1969.
[26] A. E. Taylor. The differential: Nineteenth and twentieth century developments. Arch. Hist.
Exact Sci., 12:355–383, 1974.
[27] A. N. Michel and C. J. Herget. Applied Algebra and Functional Analysis. Dover Publications,
Inc., 1981.
[28] J. M. Ortega and W. C. Rheinboldt. Iterative Solution of Nonlinear Equations in Several
Variables. Academic Press, New York, NY, 1970.
[29] D. Margetis, M. Aziz, and H. Stone. Continuum approach to profile scaling in nanostructure
decay. Phys.Rev.B, 71:165432, 2005.
[30] D. Margetis, P. Fok, M. Aziz, and H. Stone. Continuum theory of nanostructure decay via a
microscale condition. Submitted for review.
[31] M. Z. Bazant, K. T. Chu, and B. J. Bayly. Current-voltage relations for electrochemical thin
films. SIAM J. Appl. Math., 65:1463–1484, 2005.
[32] K. T. Chu and M. Z. Bazant. Electrochemical thin films at and above the classical limiting
current. SIAM J. Appl. Math., 65:1485–1505, 2005.
[33] A. Griewank. Evaluating Derivatives: Principles and Techniques of Algorithmic Differentia-
tion. SIAM, Philadelphia, PA, 2000.
[34] P. Hovland and B. Norris. Argonne national laboratory computational differentiation project,
2006. http://www-fp.mcs.anl.gov/autodiff/.

You might also like