+ All Categories
Home > Documents > Automated solving of constant-coefficients second-order linear ...

Automated solving of constant-coefficients second-order linear ...

Date post: 23-Apr-2023
Category:
Upload: khangminh22
View: 0 times
Download: 0 times
Share this document with a friend
14
Automated solving of constant-coefficients second-order linear PDEs using Fourier analysis E Roque a , JA Vallejo b,<,1 a Centro de Investigación y Estudios Avanzados Instituto Politécnico Nacional, Libramiento Norponiente 2000, Fracc. Real de Juriquilla. CP 76230 Santiago de Querétaro (Qro) México b Facultad de Ciencias, Universidad Autónoma de San Luis Potosí, Av Chapultepec 1570 Col. Lomas del Pedregal CP 78295 San Luis Potosí (SLP) México ARTICLE INFO Keywords: Sturm-Liouville Problem Computer Algebra Systems Automated Computations. ABSTRACT After discussing the limitations of current commercial software, we provide the details of an im- plementation of Fourier techniques for solving second-order linear partial differential equations (with constant coefficients) using a computer algebra system. The general Sturm-Liouville prob- lem for the heat, wave and Laplace operators on the most common bounded domains is covered, as well as the general second-order linear parabolic equation with constant coefficients, which includes cases such as the convection-diffusion equation by reduction to the heat equation. 1. Introduction The need for explicit solutions of differential equations (be them ordinary or partial) arises in the everyday practice of physicists, engineers and scientists in general. The class of ordinary differential equations that can be solved by elementary methods, mainly clever changes of variables and linear algebra, is quite ample and, accordingly, there exists a vast amount of software devoted to finding both their explicit and numerical solutions. This is in contrast with the case of partial differential equations (PDEs). Here, solution techniques are more advanced, involving Fourier analysis for bounded domains and integral transforms in the unbounded case 2 and, although there is a good deal of software packages related to numerical computations (most of them using the finite element method), there is a shortage of options for finding explicit analytic solutions. In fact, to the best of our knowledge, only Maplesoft’s Maple™ and Wolfram’s Mathematica™ –both closed and proprietary software– are capable of this task. Both are excellent general purpose computer algebra systems (CAS) and do their job fast and efficiently, so one could wonder what is the motivation for considering the problem of automated solution of PDEs or thinking it is not already solved. To this question we can offer the following answers: 1. Although they are very good at finding solutions, still there are examples where Maple™ or Mathematica™ can not find it (see examples in subsection 4.2). In those cases, it is very difficult to determine the origin of the failure, as both are closed source packages. The user can have a hard time trying to determine whether there is a problem in the formulation of the problem or in the method of solution. 2. Proprietary software usually has a cost, and this case is no exception. While both packages are worth their price, this can be a serious hurdle for people working in underdeveloped countries, students in general or even freelancers for whom an open source alternative would be desirable. 3. From a pedagogical point of view, the use of closed source software is like using a black box for finding answers. The teacher can expose an algorithm in the classroom and then say it is exemplified by the output, but really < Corresponding author [email protected] (E. Roque); [email protected] (J. Vallejo) http://galia.fc.uaslp.mx/~jvallejo (J. Vallejo) ORCID(s): 0000-0002-5463-758X (E. Roque); 0000-0002-9508-1549 (J. Vallejo) 1 Supported by a research grant from the Consejo Nacional de Ciencia y Tecnología (México) code A1-S-19428. 2 In this paper we restrict our attention to classical solutions, thus leaving aside considerations regarding weak solutions and the use of such tools as distribution theory. E Roque and JA Vallejo Page 1 of 14 arXiv:2004.02604v1 [math.NA] 2 Apr 2020
Transcript

Automated solving of constant-coefficients second-order linearPDEs using Fourier analysisE Roquea, JA Vallejob,∗,1aCentro de Investigación y Estudios AvanzadosInstituto Politécnico Nacional,Libramiento Norponiente 2000, Fracc. Real de Juriquilla.CP 76230 Santiago de Querétaro (Qro) MéxicobFacultad de Ciencias, Universidad Autónoma de San Luis Potosí,Av Chapultepec 1570 Col. Lomas del PedregalCP 78295 San Luis Potosí (SLP) México

ART ICLE INFOKeywords:Sturm-Liouville ProblemComputer Algebra SystemsAutomated Computations.

ABSTRACTAfter discussing the limitations of current commercial software, we provide the details of an im-plementation of Fourier techniques for solving second-order linear partial differential equations(with constant coefficients) using a computer algebra system. The general Sturm-Liouville prob-lem for the heat, wave and Laplace operators on the most common bounded domains is covered,as well as the general second-order linear parabolic equation with constant coefficients, whichincludes cases such as the convection-diffusion equation by reduction to the heat equation.

1. IntroductionThe need for explicit solutions of differential equations (be them ordinary or partial) arises in the everyday practice

of physicists, engineers and scientists in general. The class of ordinary differential equations that can be solved byelementary methods, mainly clever changes of variables and linear algebra, is quite ample and, accordingly, thereexists a vast amount of software devoted to finding both their explicit and numerical solutions. This is in contrastwith the case of partial differential equations (PDEs). Here, solution techniques are more advanced, involving Fourieranalysis for bounded domains and integral transforms in the unbounded case2 and, although there is a good dealof software packages related to numerical computations (most of them using the finite element method), there is ashortage of options for finding explicit analytic solutions. In fact, to the best of our knowledge, only Maplesoft’sMaple™ and Wolfram’s Mathematica™ –both closed and proprietary software– are capable of this task. Both areexcellent general purpose computer algebra systems (CAS) and do their job fast and efficiently, so one could wonderwhat is the motivation for considering the problem of automated solution of PDEs or thinking it is not already solved.To this question we can offer the following answers:

1. Although they are very good at finding solutions, still there are examples where Maple™ or Mathematica™can not find it (see examples in subsection 4.2). In those cases, it is very difficult to determine the origin of thefailure, as both are closed source packages. The user can have a hard time trying to determine whether there isa problem in the formulation of the problem or in the method of solution.

2. Proprietary software usually has a cost, and this case is no exception. While both packages are worth theirprice, this can be a serious hurdle for people working in underdeveloped countries, students in general or evenfreelancers for whom an open source alternative would be desirable.

3. From a pedagogical point of view, the use of closed source software is like using a black box for finding answers.The teacher can expose an algorithm in the classroom and then say it is exemplified by the output, but really

∗Corresponding [email protected] (E. Roque); [email protected] (J. Vallejo)http://galia.fc.uaslp.mx/~jvallejo (J. Vallejo)

ORCID(s): 0000-0002-5463-758X (E. Roque); 0000-0002-9508-1549 (J. Vallejo)1Supported by a research grant from the Consejo Nacional de Ciencia y Tecnología (México) code A1-S-19428.2In this paper we restrict our attention to classical solutions, thus leaving aside considerations regarding weak solutions and the use of such

tools as distribution theory.

E Roque and JA Vallejo Page 1 of 14

arX

iv:2

004.

0260

4v1

[m

ath.

NA

] 2

Apr

202

0

Automated solving of PDEs using Fourier analysis

there is no clue about what is being actually computed, if there is any mathematical trick used which is notcontemplated in the algorithm, or if use is made of pre-computed tables of particular cases, and so on.

4. Lastly, the problem is interesting in itself from amathematical and computational perspective, due to the blendingof purely symbolic and numeric algorithms it requires, as will be seen in detail below.

These reasons led us to write a library, called pdefourier, for solving the general Sturm-Liouville problem forthe heat, wave and Laplace operators with sources, as well as some particular problems reducible to these, such asthe convection-diffusion equation. Our particular implementation uses the open source Maxima CAS [7], which has aprogramming language very closely tied to LISP and should be translatable to any other CAS or programming languagein general, such as Python or Symbolic C++, without difficulty.

In Section 2 we comment on the challenges posed by the automated computation of solutions using Fourier tech-niques in general. By including examples of computations usingMathematica™ , we present a panorama of the currentstate of the art3.Remark. In what follows, all Mathematica™ commands have been executed using version 12.1.0.0 on a Linux plat-form. The Maxima commands have been executed on the same Linux machine, with version 5.42.2 compiled againstthe LISP implementation SBCL 1.4.4. It is assumed that the package pdefourier has already been loaded. Forinstallation instructions see Appendix A.

Section 3 describes how we handle the issues mentioned in Section 2, detailing some of the core features of thelibrary, and we finish in Section 4 by showing some examples and applications.

2. Sturm-Liouville problems and eigenfunctions expansionNotice that, from a mathematical point of view, the basic models given by the heat, wave and Laplace equations are

all second-order linear partial differential equations with constant coefficients. They are supplemented by some initialand/or boundary conditions (the general situation contemplates both, and it is known as an IBVP or initial-boundaryvalue problem), and in this work we will assume that the problem is set on a bounded spatial domain [0, L] ⊂ ℝ, sothese conditions will be given at the boundary points x = 0, x = L (the only exception being Laplace’s equation, whichwill be considered on a plane domain). The general problem for the heat and wave equations can be written as:

u = Q(x, t)u(x, 0) = F (x)ux(x, 0) = G(x)�1u(0, t) + �1ux(0, t) = ℎ1(t)�2u(L, t) + �2ux(L, t) = ℎ2(t) ,

(1)

where denotes either the heat or the wave operator. In the case of the Laplace’s equation we consider a wider classof plane domains (rectangles, disks, wedges, annuli) and boundary conditions. In a rectangular domain [0, a] × [0, b]we consider the problem with mixed boundary conditions of the form:

Δu = 0 �, �, , � ∈ {0, 1}(1 − �)u(x, 0) + �uy(x, 0) = f0(x)(1 − �)u(x, b) + �uy(x, b) = fb(x)(1 − )u(0, y) + ux(0, y) = g0(y)(1 − �)u(a, y) + �ux(a, y) = ga(y)

(2)

On the remaining domains, the Laplace equation is solved in polar coordinates with Dirichlet and Neumann bound-ary conditions; the only exception being the case of an annular domain, where only Dirichlet boundary conditions are

3Wemust insist in this aspect, since nothing could be further from our minds than to do a comparison test or a benchmark against a commercialsoftware, supported by a whole team of scientists.

E Roque and JA Vallejo Page 2 of 14

Automated solving of PDEs using Fourier analysis

considered. Here is a summary of the cases:

urr +1r ur +

1r2 u�� = 0

(r, �) ∈ (0, R1] × [0, �[, 0 < � ≤ 2�, 0 < R1 (Disk/Wedge)(r, �) ∈ [R1, R2] × [0, 2�[, 0 < R1 < R2 (Annulus)Dirichlet boundary conditions:u(r, 0) = 0 = u(r, �) if � < 2� (Wedge)u(R1, �) = f (�) (Annulus/Disk/Wedge)u(R2, �) = g(�) (Annulus)Neumann boundary conditions:u(r, 0) = 0 = u(r, �) if � < 2� (Wedge)ur(R1, �) = f (�) (Disk/Wedge)

(3)

A common procedure to solve these equations is to apply separation of variables: Writingu(x, t) = X(x)T (t) ,

and denoting generically X or T by �, leads to a regular Sturm-Liouville problem whose general form is� ≐ (p ⋅ �′)′ + (q + �r)� = 0 , (4)

where p, r > 0 are positive real functions, and p′, q, r are continuous on [0, L]. The abstract theory of Sturm-Liouvilleoperators is very well developed (see [1, 3]), and its main result can be summarized as follows:Theorem 2.1. Let be a Sturm-Liouville operator as in (4), subject to the boundary conditions derived from those in(1) in the homogeneous case. Assume that, for i ∈ {1, 2},

|�i|2 + |�i|

2 ≠ 0 . (5)Then, the following hold:

1. All the eigenvalues � are real and form a denumerable set.2. The set of all eigenfunctions, , is an orthogonal set.3. The set is complete in the space of square-integrable functions L2([0, L]).4. The sequence (�n) diverges to +∞ and is bounded from below.5. If �i, �i, p,−q are all non-negative, then the eigenvalues �n are all non-negative.Notice that the preceding theorem applies to homogeneous initial and boundary conditions and Q = 0. To deal

with the non-homogeneous case , we use the method of eigenfunction expansion or finite cosine or sine transform (see[6, 9]). Once we know how to deal with the general Sturm-Liouville problem for the heat, wave and Laplace operators,we can solve some other problems that can be reduced to one of these. The cases of the convection-difussion equationand heat loss through lateral boundaries are then particular cases. Thus, consider the general expression of a second-order linear parabolic equation with constant coefficients with sources:

ut = �uxx + vux + cu +Q(x, t) (6)Let us apply the change of variable

u = we�(x,t) ,

where

�(x, t) = (c − v2

4�)t − v

2�x

E Roque and JA Vallejo Page 3 of 14

Automated solving of PDEs using Fourier analysis

Substituting into (6) we getQ = ut − �uxx − vux − cu= e�(wt − �wxx)

hence, the original equation in terms of the new dependent variable reduces to the heat equation with sourceswt = �wxx + e−�Q

Of course, the initial and boundary conditions for u(x, t) must be transformed accordingly into conditions forw(x, t).

The Sturm-Liouville theory is the basic tool used in our Maxima package pdefourier. The algorithm can besummarized as follows: we first solve the eigenvalue problem associated to (4), normalize the corresponding eigen-functions and then proceed to develop the solution to (1) in term of eigenfunctions, taking non-homogeneous conditionsinto account with the use of the methods commented above. These steps involve some delicate issues that we discussnext.

Singular values of the Fourier coefficients. The computation of Fourier coefficients in a CAS can be done usingintegration formulas. Particular care must be taken to separate singular values that lead to divergences in the generalexpressions of the Fourier coefficients. There are two types of special input functions whose Fourier coefficientsmust be calculated separately, namely, the functions belonging to one of the cosine, sine, trigonometric or complexorthogonal systems or a product of a polynomial with them. In these cases, the Fourier coefficients have a generalexpression

C�(n)

with � a polynomial, which is only valid for the non-singular values of n. The singular values must be treated separately.This process is, of course, transparent to the user, but lies at the bottom of the difficulties experienced by such maturesoftware as Mathematica™ . Due to the widespread of this CAS, we will use it to get a benchmark for our libraryperformance.

To get a sense of the kind of problems we are talking about, recall the definition of the Fourier coefficients of a2�−periodic function f (x) (we consider the case L = � for simplicity):

a0 =12� ∫

−�f (x) dx , an =

1� ∫

−�f (x) cos(nx) dx , bn =

1� ∫

−�f (x) sin(nx) dx .

where n is a natural number. In practice, the explicit computations of these coefficients depends heavily on the orthog-onality relations (m, n ≥ 1)

1� ∫

−�cos(mx) cos(nx) dx = �mn ,

1� ∫

−�sin(mx) sin(nx) dx = �mn .

However, most computer algebra systems fail to recognize the possibility that m = n. Thus, Mathematica™ givesIn[1]:= Integrate[Cos[m x] Cos[n x], {x, -Pi, Pi}]Out[1]= (2 m Cos[n \[Pi]] Sin[m \[Pi]] - 2 n Cos[m \[Pi]] Sin[n \[Pi]])/(m^2 - n^2)

and the same is true of Maxima:(%i1) integrate(cos(m*x)*cos(n*x),x,-%pi,%pi);(%o1) (2*((n-m)*sin(%pi*n+%pi*m)+(n+m)*sin(%pi*n-%pi*m)))/(2*n^2-2*m^2)

This fact has many consequences due to the presence of singular values of n, as pointed above. Take as an examplethe computation of Fourier coefficients for

f (x) = 3x2 cos(7x) . (7)

E Roque and JA Vallejo Page 4 of 14

Automated solving of PDEs using Fourier analysis

Using the trigonometric identity

cos � cos� = 12cos(� − �) + 1

2cos(� + �)

and integrating by parts, it is straightforward to obtain

a0 = −649

an =

−12(n2 + 49)(−1)n

(n − 7)2(n + 7)2if n ≠ 7

98�2 + 398

if n = 7bn =0

Mathematica™ fails to compute correctly the Fourier coefficients directly from the integral formulas because itdoes not recognize the singularity corresponding to n = 7:In[2]:= Assuming[Element[n,Integers],1/Pi Integrate[Cos[n x] 3 x^2 Cos[7 x],{x,-Pi,Pi}]]Out[2]= -((12 (-1)^n (49 + n^2))/(-49 + n^2)^2)

and so does Maxima:(%i2) block([n],declare(n,integer),

factor(integrate(cos(n*x)*3*x^2*cos(7*x),x,-%pi,%pi)/%pi));(%o2) -(12*(n^2+49)*(-1)^n)/((n-7)^2*(n+7)^2)

Equivalence of trigonometric expressions. Another source of concern when dealing with trigonometric expres-sions is the existence of multiple, equivalent ways of writing them. This is a well-known issue in different CASs. Theset of heuristics rules Mathematica™ appears to use inside its Fourier coefficients built-in functions try to supportcommon special cases, but are highly sensitive to the way the input is written and do not take advantage of the linearityof the integral nor distribute over subintervals of piecewise-defined functions. For instance, using equation (7) in thecase � = ' we get:

cos(�)2 = 12+ 12cos (2�) (8)

For illustration purposes, here are the results given by MathematicaTM for the Fourier cosine coefficients of eachside of the equation.In[3]:=FourierCosCoefficient[Cos[x]^2, x, n]Out[3]:=0In[4]:=FourierCosCoefficient[(1+Cos[2x])/2, x, n]Out[4]:=1/2 (DiscreteDelta[-2 + n] + 2 DiscreteDelta[n])

Moreover, its routines do not take advantage of the linearity, as a slight change in the input function prevents themfrom working:In[3]:=FourierCosCoefficient[(2+Cos[2 x])/2,x,n]Out[3]:=0

The strategy followed in our implementation of the package is to internally transform any trigonometric functioninto its canonical form, so it becomes easy to decide whether or not the input contains an expression whose Fouriercoefficients have singular values using the pattern matching capabilities of the Maxima CAS, as described in thefollowing section.

Piecewise-defined functions. Let us point that, in applications, many of the functions we deal with are piecewisedefined, and this poses its own challenges. Maxima currently does not have built-in support for piecewise-defined

E Roque and JA Vallejo Page 5 of 14

Automated solving of PDEs using Fourier analysis

expressions which are of particular importance in engineering and physics applications. We developed another pack-age called piecewise automatically loaded by pdefourier to deal with this kind of functions. In particular, we areable to detect the parity of a piecewise-defined function defined on an interval [−L,L] by the means of comparisonof subintervals allowing us to simplify the computation of Fourier coefficients of odd or even functions. Also, wetake advantage of the linearity and interval addition properties of the integral; because of this, our pattern matchingrules work even with piecewise-defined functions and equivalent trigonometric expressions as we will see in Section 4.

3. Computation of the Fourier coefficients and seriesThe aim of this section is to explain the strategies followed in the implementation of our package to tackle the

different challenges we have showed in the previous section.3.1. Piecewise-defined functions

Inherited from Lisp, Maxima’s main data structures are lists, thus the natural way to proceed was to translate apiecewise-defined function to a list and viceversa. Having a way to convert a piecewise expression to a list, it isstraightforward to write some other functions to make operations between them or to compute the derivative and theintegral of a piecewise expression written as a list. Although the package piecewise is able to work in more generalsettings, we restrict ourselves here to show only how the package works in a bounded interval. The remaining detailsare available in the package documentation. For illustration purposes, consider an if-else expression of the form:

if x>=a0 and x<=a1 then expr1 elseif ... elseif x>an−1 and x<=an then exprn

We impose the restrictions ai ≤ ai+1, ai ∈ ℝ, to avoid potential issues with the detection of valid intervals in allthe equivalent ways of writing them, and to do it efficiently. The output returned by pw2list has the form:

[[[a0, a1], expr1], [[a1, a2], expr2, ]…]The approach of internally working with lists instead of if-else expressions is particularly handy since the Max-

ima language supports the functional programming paradigm so once we have proper detection of special cases withpattern-matching, we can easily map the routines to each subinterval.3.2. Computation of Fourier coefficients

As mentioned in the preceding Section, the product of a polynomial by a trigonometric function gives rise tosingular values when determining Fourier coefficients, having as particular cases trigonometric functions whose wavenumber is a multiple of �∕L. Because of the linearity of the integral, using trigonometric canonical forms it is enoughto detect the following patterns:

xr cos(m�xL

), xr sin(m�xL

), cos(m�xL

), sin(m�xL

), r, m ∈ ℕ

To do so, we used the Maxima built-in commands defmatch and matchdeclare. Then, two similar strategieswere followed depending on the input expression being piecewise-defined or not. Algorithm 1 describes the stepsfollowed in our implementation to calculate the Fourier coefficients. Of course, when the input function is piecewise-defined the procedure described in the algorithm must be applied to each subinterval of the domain.

The same ideas also apply for the case of the complex, sine or cosine coefficients; the only difference is in the waythe output is returned to the user (see Table 1).

Also notice that, by using expressions instead of declared functions, we are capable to treat arbitrary, non-evaluatedfunctions such as a symbolic f (x). The capabilities of Maxima, however, allows us to evaluate these when required.3.3. Fourier series

Following our policy of efficiency, Fourier series are obtained using an expansion routine of the Fourier coefficients.We can suspect that Mathematica™ does not perform an expansion of the coefficients to obtain the Fourier series, butcomputes them one by one inside the FourierSeries function, for two reasons: First, because Mathematica™ onlyworks with truncated series and so a general expression for the coefficients is not needed and second, because thisE Roque and JA Vallejo Page 6 of 14

Automated solving of PDEs using Fourier analysis

Algorithm 1: Computation of Fourier coefficientsInput: expression expr; variable var, semi-length of interval LOutput: A list of Fourier coefficients of the form [[a0, an, bn], l.s.v]l.s.v=list of singular values

1 Apply simplification functions to convert trigonometric expressions appearing in expr into their canonical form.2 Expand expr fully and convert the expanded expression term1 +…+ terms into a list [term1,… , terms].3 Apply a heuristic routine with pattern matching capabilities to each element of the list to compute

an(termk), bn(termk) and apply an auxiliary function which searches the set of indices having singular values,if any, of an, bn and store it in a list A.

4 Sum over k both an(termk), bn(termk) to obtain the final answer for an, bn and compute separately the Fouriercoefficients of the indices appearing in A storing the result in the list of singular values. The list of singularvalues, if any, is written as follows [[j, aj , bj],…], otherwise, an empty list [ ] is returned.

Type Command Answer format List of s.v format

Trigonometric fouriercoeff(expr, var, L) [[a0, an, bn], list of s.v] [ ] / [[j, aj , bj],…]Complex cfouriercoeff(expr, var, L) [[c0, cn], list of s.v] [ ] / [[j, cj],…]Cosine fouriercoscoeff(expr, var, L) [[a0, an], list of s.v] [ ] / [[j, aj],…]Sine fouriersincoeff(expr, var, L) [[bn], list of s.v] [ ] / [[j, bj],…]

Table 1Output formats for the Fourier coefficients (s.v= singular values).

approach avoids the problems associated to simplification of symbolic integrals using assumptions. Nevertheless thisstrategy is inefficient because it does not take advantage of previously computed Fourier coefficients. As we have seenbefore, Mathematica™ can not obtain correctly the cosine coefficients of cos2 x, but if we compute the first five termsof the cosine series of this function we get the right answer:In[10]:=FourierCosSeries[Cos[x]^2,x,5]Out[10]:=1/2+1/2Cos[2x]

In our case the upper limit of summation can be a positive integer or infinite. In the first case, a truncated series isreturned; in the second, a symbolic series is displayed. In Table 2 we summarize the syntax for the expansion routinesalong with the different Fourier series commands, see also Table 1 for comparison.

Expansion routine Series

fouriercoeff_expand(list of coeff,var,L,N) fourier_series(expr,var,L,N)cfouriercoeff_expand(list of coeff,var,L,N) cfourier_series(expr,var,L,N)fouriersincoeff_expand(list of coeff,var,L,N) fouriersin_series(expr,var,L,N)fouriercoscoeff_expand(list of coeff,var,L,N) fouriercos_series(expr,var,L,N)

Table 2Expansion routines and Fourier series syntax in pdefourier.

3.4. Numerical aspectsThe determination of Fourier coefficients in the case of the 2D wave equation requires computing the zeros of

Bessel’s functions. Unfortunately, Maxima ’s numerical capabilities are rather limited, in particular, it does not haveany built-in function for this task (although it has implemented the Bessel functions of first and second kind). Thus,it has been necessary to write a dedicated function for computing these zeros, and in the process of doing so severalsurprises regarding the implementation of Bessel functions in commercial CASs arose.

E Roque and JA Vallejo Page 7 of 14

Automated solving of PDEs using Fourier analysis

Our solution for determining the zeros of J�(x) and J ′�(x) is based on the papers [2] and [4], which allows for asimple and efficient implementation of their algorithms, the main step being the computation of eigenvalues of certainmatrices (we do this by importing the function dgeev from Netlib’s lapack package). As we are interested exclusivelyin real zeros, we restrict the order in J�(x) to � > −1 (Lommel’s theorem), but otherwise we impose no restrictionson �. Thus, for example, the third zero of J1∕2(x) is returned by the function BesselJzeros (mimicking the namesin Maple™ and Mathematica™ ):(%i1) load(pdefourier)$(%i2) BesselJZeros(1/2,3);(%o2) 9.42477796076938

and the third zero of J146225(x) is(%i3) BesselJZeros(146225,3);(%o3) 146456.0070601201

While Maple™ gives the result (even with better precision) effortlessly, to our surprise Mathematica™ could notcalculate it, neither did the web-based engine Wolfram Alpha. Probably, this is due to the fact that they are using somevariant of MacMahon formula, which fails for higher orders (see the comments in [10]). Other alternatives, such asHalley’s method, also put a bound on the order, as it occurs in Matlab [8].

As mentioned, the algorithms in [2, 4] can be used to generate the zeros of J ′�(x). This is done by the functionBesselJdiffZeros. The following table gives the first 5 zeros of the derivatives of J ′�(x) for 0 ≤ � ≤ 4, and is to becompared with the one in [11]:(%i4) transpose(apply(matrix,makelist(BesselJdiffZeros(j,5,all),j,0,4)));(%o4) matrix([3.831705970207512,1.84118378134066,3.05423692822714,4.201188941210528,5.317553126083997],[7.015586669815619,5.331442773525031,6.706133194158456,8.015236598375953,9.28239628524161],[10.17346813506272,8.536316366346284,9.96946782308759,11.345924310743,12.68190844263889],[13.32369193631421,11.70600490259207,13.17037085601612,14.58584828616704,15.96410703773154],[16.47063005087759,14.86358863390901,16.34752231832178,17.78874786606648,19.19602880004888])

Up to our knowledge, Maple™ does not have a similar function for computing the zeros of derivatives of Besselfunctions.3.5. Solution of PDEs

In developing our library, we focused on solving the three main second-order linear partial differential equationswith constant coefficients, namely, the heat, wave and Laplace equations. The mathematical details can be found in anystandard textbook on PDEs or Fourier Analysis (for instance, see [6, 9]). Here, we just briefly discuss some technicalaspects of the implementation, a list of examples will be given in the next Section.

It has been mentioned that Fourier series are obtained by performing an expansion of the Fourier coefficients. Thisapproach is multipurpose. It is also useful to code the solution of the PDEs in an easier way. Although the packagecan solve the heat equation with a heat source Q(x, t), we want to illustrate how the expansion sub-routines facilitatethe process of finding solutions with a simpler instance of the general equation. Consider the following IBVP:

ut = �uxx (x, t) ∈ [0, L] ×ℝ+

u(x, 0) = f (x)u(0, t) = 0u(L, t) = 0

the solution is then given by

u(x, t) =∞∑

n=1Bn exp[−n2(

��L)2t] sin n�x

L

E Roque and JA Vallejo Page 8 of 14

Automated solving of PDEs using Fourier analysis

Bn =2L ∫

L

0f (x) sin n�x

L

Notice that for our purposes, it will be sufficient if we create a list of the form [[Cn(t)], [ ]∕[j, Cj(t)]] where Cn(t) =Bn exp[−n2(

��L )

2t] and then use the expansion routine corresponding to a Fourier sine series on the interval [0, L] andthe space variable x. For instance, if we consider f (x) = x2(1 − x), L = 1, � = 1, a solution to the IBVP can beobtained in a few lines of code:(%i2) g(x):=if (0<=x and x<=1) then x^2*(1-x)$(%i3) [[Bn],lsv]:fouriersincoeff(g(x),x,1)$(%i4) Cn:Bn*exp(-n^2*%pi^2*t)$(%i5) fouriersincoeff_expand([[Cn],[]],x,1,inf);(%o5)

−4∑∞n=1

(2(−1)n+1)%e−�2 n2t sin (�nx)n3

�3

Here the list of singular values was empty (obviously), and no further work was required. The library commandmixed_heat automates all the process in the most general setting.

Similar methods to obtain solutions for the three equations with different types of boundary conditions and domainshave been implemented, dealing with general expressions (piecewise-defined or not) and taking care of the possiblesingular values in the coefficients.

4. Some examples4.1. Fourier coefficients and series

Let f (x) be as in (7). Then we have the following:(%i2) fouriercoeff(3*x^2*cos(7*x),x,%pi);(%o2)

[[− 649,12

(

n2 + 49)

(−1)n+1

n4 − 98n2 + 2401, 0], [[7, 98�

2 + 398

, 27]]]

Indeed, notice that (n − 7)2(n + 7)2 = n4 − 98n2 + 2401.The case where Mathematica™ fails to compute correctly the cosine coefficients of equivalent trigonometric ex-

pressions (8), is readily solved by our package:(%i3) fouriercoscoeff(cos(x)^2,x,%pi);(%o3)

[[12, 0], [[2, 1

2]]]

(%i4) fouriercoscoeff((1+cos(2*x))/2,x,%pi);(%o4)

[[12, 0], [[2, 1

2]]]

Next, we offer an example of a piecewise-defined function having singular values. We will use the commandcfouriercoeff to get the complex Fourier coefficients, so that we can compare our answer to the one returned byMathematica™.(%i5) f(x):=if x>= -%pi and x<0 then 0 elseif x>=0 and x<%pi then sin(3*x)$(%i6) cfouriercoeff(f(x),x,%pi);(%o6)

E Roque and JA Vallejo Page 9 of 14

Automated solving of PDEs using Fourier analysis

[[ 13�,−3(

(−1)n + 1)

2�(

n2 − 9) ], [[3,−%i4

]]]

However, Mathematica TM is not able to detect the singular value of the coefficient when n = 3:In[8]:=f[x]:= Piecewise[{{0,-Pi<=x<0}, {Sin[3x],0<=x<Pi}}]In[9]:=FourierCoefficient[f[x], x, n]

−3 ((−1)n + 1)2�

(

n2 − 9)

Now, we consider an example of how Fourier series are displayed symbolically. If g(x) = x4 on [−�, �] we get theanswer in the form used in textbooks:(%i7) fourier_series(x^4,x,%pi,inf);(%o7)

8

( ∞∑

n=1

(

�2 n2 − 6)

(−1)n cos (nx)n4

)

+ �4

5

Lastly, we show an example of how to use the expansion routines to obtain the Fourier series, truncated or not, andhow they handle singular values in the Fourier coefficients when displaying an infinite series.(%i8) fcoeff:fouriersincoeff(x*cos(3*x),x,%pi);(fcoeff)

[[2n (−1)n

n2 − 9], [[3,−1

6]]]

(%i9) fouriersincoeff_expand(fcoeff,x,%pi,5);(%o9)

−5 sin (5x)

8+8 sin (4x)

7−sin (3x)6

−4 sin (2x)

5+sin (x)4

(%i10) fouriersincoeff_expand(fcoeff,x,%pi,inf);(%o10) "The sum is over |N-{3}"

2

( ∞∑

n=1

n (−1)n sin (nx)n2 − 9

)

−sin (3x)6

It is important to notice that displaying infinite series correctly has been a source of troubles in different CAS.This is mainly due to the fact that they are not evaluated, only displayed symbolically, so a simplification evident for ahuman might not be performed by a CAS.

For illustration purposes, suppose that we want to compute the Fourier series of ℎ(x) = sin 15x on the interval[−�, �]. It is obvious that its Fourier series is exactly equal to ℎ(x), because its Fourier coefficients are a0 = 0, an =0, bn = �15n and we have:

ℎ(x) ∼∞∑

n=1�15n sin nx = sin 15x

However, infinite sums of expressions containing Kronecker delta functions are really hard to simplify to a singleterm, because it must be verified that the only index that does not vanish is indeed contained in the set of indices overwhich we are considering the sum. Integration routines in different CAS sometimes return the result for bn in termsof some sort of Kronecker delta (Mathematica TM returns it in terms of DiscreteDelta), which complicates the taskof obtaining the Fourier series by an expansion of the coefficients. Following our approach, we avoid the issue of theevaluation of Kronecker delta functions inside an infinite sum:(%i11) fourier_series(sin(15*x),x,%pi,inf);(%o11) sin(15*x)

Notice that, as we just saw in the examples above, when the list of singular values is not empty, the library printsa message warning about the set of indices excluded in the infinite sum.E Roque and JA Vallejo Page 10 of 14

Automated solving of PDEs using Fourier analysis

4.2. Partial differential equationsWe will show some examples involving each type of equation (parabolic, hyperbolic and elliptic). Although

pdefourier is able to solve these equations with many more boundary conditions, the ones given here are meantto give a panorama about how to use the package to solve PDEs.4.2.1. The linear second-order parabolic equation

Consider the general problem:⎧

ut = �uxx + vux + cu +Q(x, t) on (x, t) ∈ [0, L] ×ℝ+

u(x, 0) = F (x)�1u(0, t) + �1ux(0, t) = ℎ1(t)�2u(L, t) + �2ux(L, t) = ℎ2(t)

The syntax for solving it ismixed_parabolic(Q(x,t),F(x),a1,b1,a2,b2,h1(t),h2(t),x,t,L,k,v,c,ord),

where ord can be inf, for the complete series solution, or a natural number, for the truncated series.As an example, we will solve a problem with homogeneous boundary conditions⎧

ut = �uxx − 9ux on (x, t) ∈ [0, 1] ×ℝ+

u(x, 0) = e45x∕10(5 sin(�x) + 9 sin(2�x) + 2 sin(3�x))u(0, t) = 0)u(1, t) = 0

Remark. In comparing results with Maple™ 2020 and Mathematica™ we imposed a time limit of 600 seconds (realtime) to get an answer from both. If no answer was returned in such time, we considered it a failure. Maple™ reachedthat time limit without giving an answer; however, Mathematica™ solved it giving the same answer as below.

With pdefourier we would do(%i1) load(pdefourier)$(%i2) mixed_parabolic(0,exp(45*x/10)*(5*sin(%pi*x)+9*sin(2*%pi*x)+2*sin(3*%pi*x)),

1,0,1,0,0,0,x,t,1,1,-9,0,inf);(%o2)

e9x2 −

81t4

(

2e−9�2t sin (3�x) + 9e−4�

2t sin (2�x) + 5e−�2t sin (�x)

)

4.2.2. Laplace equationHere we consider the Laplace equation on a wedge with Neumann conditions:⎧

urr +1r ur +

1r2 u�� = 0 on (r, �) ∈ [0, R] × [0, �], 0 < � < 2�

u(r, 0) = 0u(r, �) = 0ur(R, �) = f (�)

Mathematica™ is unable of solving it (tested on versions 12.0 and 12.1). The syntax for Neumann problems inpdefourier is

neumann_laplace_wedge(R,alpha,f(theta),theta,ord).

In this example we will consider4 � = �∕2, R = 1, and an arbitrary function f (�):4The use of the percent sign is useful in some Maxima’s graphical interfaces to get the symbol displayed as a Greek character.

E Roque and JA Vallejo Page 11 of 14

Automated solving of PDEs using Fourier analysis

(%i3) neumann_laplace_wedge(1,%pi/2,f(%theta),%theta,inf);(%o3)

2�

∞∑

n=1

sin (2�n) ∫�20 f (�) sin (2�n)d� r2n

n

4.2.3. Wave equationFor this example, we will consider the wave equation with homogeneous boundary conditions and a driving term,

a problem whose general expression is:⎧

utt(x, t) = c2uxx(x, t) + F (x, t) (x, t) ∈ [0, L] ×ℝ+

u(x, 0) = f (x)ut(x, 0) = g(x)u(0, t) = 0 u(L, t) = 0

The syntax for solving it using pdefourier isdirichlet_wave(F(x,t),f(x),g(x),h_1(t),h_2(t),x,t,L,c,ord).

If F (x, t) = cos(!t)r(x) and g(x) = 0, then:(%i4) assume(t>0)$(%i5) dirichlet_wave(r(x)*cos(%omega*t),f(x),0,0,0,x,t,L,c,inf);(%o5)

∑∞n=1 sin(

�nxL )

(

(2L2 cos(�cntL ) − 2L2 cos(!t)) ∫ L0 r(x) sin(�nxL )dx)

�2Lc2n2 − L3!2

∑∞n=1(2L

2!2 − 2�2c2n2) sin(�nxL ) cos(�cntL ) ∫ L0 f (x) sin(�nxL )dx

�2Lc2n2 − L3!2

Since no assumptions were made about !, the solution corresponds to the case without resonance (! ≠ cn�∕L).This is Exercise 8.5.2(b) in [6]. For a different example, consider a vibrating clamped circular membrane, which ismodeled in polar coordinates as

utt = c2(

urr +1r ur +

1r2 u��

)

on (r, �, t) ∈ [0, R] × [0, 2�] × [0,∞[u(r, �, 0) = f (r, �)ut(r, �, 0) = g(r, �)u(a, �, t) = 0u(r, 0, t) = u(r, 2�, t)u�(r, 0, t) = u�(r, 2�, t)

The general case is handled by the functionwave2d_disk(c,R,f,g,k,l),

where k is the maximum order of the Bessel functions desired in the solution and l is the number of positive zeros takeninto account. In particular, for a circular membrane of unit radius, c = 1, initial shape described by f (r, �) = 1 − r4,and no initial velocities, we would issue the following commands:

E Roque and JA Vallejo Page 12 of 14

Automated solving of PDEs using Fourier analysis

(%i6) f(r,theta):=1-r^4$(%i7) g(r,theta):=0$(%i8) wave2d_disk(1,1,f,g,3,2),numer$

Remark. There is a difference between this function and the remaining ones in the library. While we used expressionsas arguments before (as sin(5*%pi*x)), here we need to enter declared functions (like f,g). Ultimately, this has todo with the fact that we are using numerical computations, but this is not an essential aspect, and as such will surelybe modified in future versions to allow for expressions in the arguments.

We have suppressed the output of the last command, since it contains a lot of terms with the aspectJj(3, 6.380161895923982 r) cos(6.380161895923982 t)2.467777882600071 ⋅ 10−15 sin(3�) .

Obviously, these are numerical artifacts coming from rounding errors (as revealed by exponents like 10−15). In thesecases, we can employ the function chop (provided in the package) analogous to the Chop[] encountered in Mathe-matica™ , to avoid rounding errors in the plot function. By default, chop discards terms of absolute value less than10−12. An additional argument can be supplied, as in chop(expr,exponent), to chop those terms whose absolutevalue is less that 10−exponent:(%i9) expr:chop(%,14);(expr) 1.366663216985716*bessel_j(0.0,2.404825557695772*r)*cos(2.404825557695772*t)-0.4858370155994775*bessel_j(0.0,5.520078110286311*r)*cos(5.520078110286311*t)

The output has a format suitable for graphical representation, or even to create an animation of the motion5:(%i10) wxanimate_draw3d(s,makelist(i/10,i,0,20),

surface_hide=true,zrange=[-1.5,1.5],ytics=0.4,xtics=0.4,color=orange,parametric_surface(r*cos(theta),r*sin(theta),subst(t=s,expr),r,0,1,theta,0,2*%pi)

),wxanimate_framerate=6$(%t10)

5Here we use the command wxanimate_draw, provided by the graphical frontend wxMaxima.

E Roque and JA Vallejo Page 13 of 14

Automated solving of PDEs using Fourier analysis

A. Installation of pdefourierThe package pdefourier is available at https://github.com/emmanuelroque/pdefourier. Once the repos-

itory has been cloned or downloaded, the package can be installed by putting a copy of the files in side a foldercontained in the environment variable file_search_maxima. In a Linux box, such a system-wide location couldbe something like /usr/share/maxima/5.42.2/share/contrib/, while in a Windows environment typically itwill be c:\Program files (x86)\Maxima-sbcl-5.42.0/share/maxima/5.42.0/share/contrib (you mayneed administrator rights in order to do that in either case). The package can then be loaded with the commandload(pdefourier)$ once inside Maxima.

References[1] M. A. Al-Gwaiz: Sturm-Liouville Theory and its Applications. Springer Verlag, London, 2008.[2] J. Grad and E. Zakrajsek: Method for evaluation of zeros of Bessel functions. J. Inst. Math. Appl. 11 (1973) 57-72.[3] G. Hellwig: Differential Operators of Mathematical Physics. Addison-Wesley, Reading (Ma.), 1967.[4] Y. Ikebe,Y. Kikuchi, I. Fujishiro: Computing zeros and orders of Bessel functions J. of Comp. and Appl. Math. 38 Issues 1-3 (1991) 169-184.[5] F. John: Partial Differential Equations. Springer Verlag, New York, 1982.[6] R. Haberman: Applied Partial Differential Equations. Pearson Education, Upper Saddle River (NJ), 2013.[7] Maxima.sourceforge.net, Maxima, a Computer Algebra System. Version 5.42.2 (2019). http://maxima.sourceforge.net.[8] J. Nicholson (2020). Bessel Zero Solver (https://www.mathworks.com/matlabcentral/fileexchange/

48403-bessel-zero-solver), MATLAB Central File Exchange. Retrieved March 31, 2020.[9] J. S. Walker: Fourier Analysis. Oxford University Press, New York, 1998.[10] G. N. Watson: The zeros of Bessel functions. Proc. of the Royal Soc. of London. Series A94 (1918) 190-207.[11] E. W. Weisstein: Bessel Function Zeros. From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/

BesselFunctionZeros.html. Retrieved March 31, 2020.

E Roque and JA Vallejo Page 14 of 14


Recommended