Solving Partial Differential Equations in Excel



Syntax

=PDSOLVE(eqns, vars, lbc, rbc, xdom, tdom, [options])


Use PDSOLVE to solve a system of partial differential equations the following form: (the system can have as many equations as needed)

u1t=f1t,x,u,ux,uxx u2t=f2t,x,u,ux,uxx

where u=[u1,u2], ux=[u1,x,u2,x], uxx=[u1,xx,u2,xx]


Initial Conditions

Initial value for each variable ui is required.

Boundary Conditions

General nonlinear boundary conditions can be specified at left and right ends of the system spatial domain [xs,xe].
Generally, for each equation fi in the system: none, one or two boundary conditions are required depending on the order of the equation.

  • If fi does not depend on ui,x and ui,xx then no boundary conditions are required for equation i.
  • If fi depends only on ui,x then only one boundary condition is required for equation i.
  • If fi depends depends on ui,xx then two boundary conditions are required for equation i.

Required Inputs

eqns a reference to the system formulas (f1, f2,..).

vars a reference to the system variables in the following order ( t, x, u1, u2,.. , u1,x, u2,x,.., u1,xx, u2,xx,.. ). The state variables (u1, u2,..) must be assigned initial conditions. An initial condition can be a constant or function of the spatial variable x.

All the variables and derivatives must be defined in the order listed above in vars regardless if they are used in the equations or not.

Variables order must be consistent with equations order. For example, given this order (t, x, u1, u2,.. ) implies ∂u1/∂t = f1, ∂u2/∂t = f2 and so forth.

lbc a reference to the left boundary condition formulas for each equation in the system. Use the string "NA" to indicate an equation has no left boundary condition.

The number of left boundary conditions must equal the number of equations in eqns. Use the string "NA" to indicate an equation has no left boundary condition.

A boundary condition formula is arranged with respect to zero on one side. For Example, suppose that the boundary condition (BC) is u1= u2+1, then the BC formula may be defined as =U1-U2-1.

rbc a reference to the right boundary condition formulas for each equation in the system.

The number of right boundary conditions must equal the number of equations in eqns. Use the string "NA" to indicate an equation has no right boundary condition.

xdom a vector defining the start and end values for the spatial domain as well as the desired solution output spatial values.

FormatRemarks
{xs, xe}The domain [xs, xe] is divided uniformly according to the allocated output array size.
{xs, xe, ndiv}The domain [xs, xe] is divided uniformly into ndiv subintervals.
{xs, x1, x2, .., xe}Solution results are reported for the supplied values only.

tdom a vector defining the start and end values for the time interval as well as the desired solution output time values.

FormatRemarks
{ti, tf}The interval [ti, tf] is divided uniformly according to the allocated output array size.
{ti, tf, ndiv}The interval [ti, tf] is divided uniformly into ndiv subintervals.
{ti, t1, t2, .., tf}Solution results are reported for the supplied values only.

tol controls the absolute and relative error tolerances for temporal integration algorithm. Default values are 1.0e-4 for relative tolerance and 1.0e-6 for absolute tolerance. Various formats are permitted as described below.

FormatRemarks
rtolRelative tolerance. Absolute tolerance value is set to rtol/100. Fixed for all variables.
{rtol, atol}Relative and absolute tolerance values. Fixed for all variables
vector of rtolicustom relative tolerance for each system variable. Absolute tolerance is set to rtoli/100.
two-column array of {rtoli, atoli}custom relative and absolute tolerances for each system variable.

ctrl a set of key/value pairs for algorithmic control as detailed below.

Description of key/value pairs for algorithmic control

KeyNDRVOUT
Admissible Values (Integer)
  1. report only (u1, u2,..) in output.
  2. include first derivatives (u1,x, u2,x,..) in output.
  3. include first and second derivatives (u1,x, u2,x,..),(u1,xx, u2,xx,..) in output.
Default Value0
RemarksThe allocated results array must have sufficient columns to hold output.

KeyFORMAT
Admissible Values (String)
XCOL1
Column 1 of the results array will contain the output spatial points.A block of columns for the solution variables at each output temporal point will be reported in order following column 1.
TCOL1
Column 1 of the result array will contain the output temporal points.A block of columns for the solution variables at each output spatial point will be reported in order following column 1.
Default ValueXCOL1
RemarksXCOL1 format is convenient to plot snapshots of solution variables at a desired time values.
TCOL1 format is convenient to plot transient views of solution variables at a desired spatial locations.
See Output Format section for more detail.
KeyALGOR
Admissible Values (String)ADAMS, BDF, RADAU5
Default ValueBDF
RemarksUse ADAMS for smooth problems, BDF or RADAU5 for stiff problems.
KeyMAXORDBDF
Admissible Values (Integer)2 ≤ MAXORDBDF ≤ 5
Default Value5
RemarksMaximum order for BDF. A higher value will increase computational cost.

KeyMAXORDADAMS
Admissible Values (Integer)2 ≤ MAXORDADAMS ≤ 12
Default Value12

KeyMAXSTEPS
Default Value100000 (Integer)
RemarksSets an upper bound on the maximum number of integration steps that can be carried out.

KeyINITSTEP
Default Value1.0e-5 (Real)
RemarksThe step size is quickly adapted. A small value is recommended if the system has fast initial transients.

KeySTEPLIMIT
Default ValueUnbounded (Real)
RemarksBy setting a limit, accuracy may be improved at the expense of speed.
KeyNNODES
Default Value50 (Integer)
RemarksNumber of mesh nodes for the spatial domain. This value has direct impact on computational cost.

KeyKORDER
Admissible Values (Integer)2 ≤ KORDER ≤ 7
Default Value4
RemarksNumber of collocation points per mesh subinterval. Higher values have direct impact on computational cost.
KeyJACSTEP
Admissible Values (Real)0 < JACSTEP < 0.1
Default ValueThe default step is computed dynamically based on machine accuracy, preset limits and function metric. For an order(1) function it is approximately 1.0e-8.
RemarksThe default value generally produces accurate approximations; however relaxing the default value may aid convergence on some problems with unknown Jacobian such as parameterized problems.

keyJACSCHEME
Admissible Values (Integer)

1 for First order Euler forward scheme

2 for Second order Euler forward scheme

Default Value1
RemarksFirst order scheme is generally sufficient.

To illustrate PDSOLVE output layout, we consider a 2-equation system with the following variables (t, x, u1, u2, u1,x, u2,x, u1,xx, u2,xx)

Snapshot View Format

The snapshot view is the default format. It allows you to easily plot snapshot views for the variables at desired time points. In this format, the solution is laid out as shown in Table 1. Output spatial points are listed in the first column starting at row 3, whereas output time points are listed in blocks in the first row starting at column 2 with variables names listed in the second row.

Table 1
ABCDEFGH..
1tt0t0t1t1t2t2..tf
2xu1u2u1u2u1u2..u2
3xs
4x1u2(x1,t0)
5x2
....
Nxe
  • The spatial and time domain are divided uniformly according to the number of allocated rows and columns for the output array. You can control x and t values by specifying your own step or custom values in parameters 4 and 5 for PDSOLVE.

  • If you allocate a larger array than needed, unused rows and columns will be filled with zeros. You can find out the minimum array size needed by evaluating PDSOLVE formula initially in one cell.

We can request to report 1st and 2nd derivative variables using the key NDRVOUT with value 1 or 2. Table 2 shows the modified layout with NDRVOUT value set to 1, in which values for u1,x, and u2,x are also included.

Table 2
ABCDEFGHIJ..
1tt0t0t0t0t1t1t1t1..tf
2xu1u2u1,xu2,xu1u2u1,xu2,x..u2,x
3xs
4x1
5x2u1(x2,t1)
....
Nxe

Transient View Format

In this format, the roles of x and t are interchanged. Output time points are displayed in the first column, whereas spatial points are displayed in the first row. This format allows you to easily plot transient views of the variables at desired spatial points.

This problem models heat transfer across a slab of thickness 1 which is insulated at the right side (x=1). The slab is initially at 0 degrees temperature. At time equals zero, the left side of the slab (x=0) is brought to 100 degrees. We compute the temperature distribution in the slab at various times.

ut=k2ux2

We solve the heat equation for the following configuration

Time period t ∈ [0,1]
Spatial range 0 ≤ x ≤ 1
Parameter k = 1
Initial condition ux,0= 100x=00else
Left boundary condition u0,t= 100
Right boundary condition ux(1,t)=0

Solution

Working with named variables t, x, u, ux, uxx corresponding to cells B2:B6, we define the input arguments to PDSOLVE as shown in Table 1, including the system equation, left and right boundary conditions formulas, and the initial value for u.

Table 1
ABCD
1VariablesParameters
2tk1
3x
4u=IF(x=0,100,0)
5ux
6uxx
7EquationsLeft BcRight Bc
8du/dt=k*uxx=u-100=ux

Next, we evaluate the array formula =PDSOLVE(B8, B2:B6, C8, D8, {0,1}, {0,1,2}) in allocated array G8:J30 and obtain the default snapshot-view formatted solution shown in Table 2. Figure 1 plots snapshot views of the temperature profiles at three time points.

  • The first argument B8 is a reference to the system RHS formula. the 2nd argument is a reference to the system variables. Alternatively, we could pass the equivalent defined names by combining them with Excel union operator as follows (t, x, u, ux, uxx) in argument 2. The 3rd and 4rth arguments are references to the left and right boundary conditions formulas.

  • We used Excel array constant syntax, {}, to pass the spatial domain [0, 1] in argument 5, and the time domain [0,1] in argument 6. Note that we have requested to report just 2 divisions in the output for the time interval [0,1] by using one of allowed formats for argument 6.

Table 2
GHIJ
8t00.51
9xuuu
100100100100
110.05097.0906199.15264
120.1094.1991798.31051
130.15091.3435297.47881
140.2088.5412896.66268
150.25085.8097395.86714
160.3083.1657395.09712
170.35080.6255794.35736
180.4078.2049193.65242
190.45075.9186892.98665
200.5073.7809592.36414
210.55071.804991.78874
220.6070.0027191.26397
230.65068.3854690.79306
240.7066.9631290.37892
250.75065.7444590.02409
260.8064.7369489.73074
270.85063.9468289.50069
280.9063.3789489.33534
290.95063.0368189.23573
301062.9225389.20245
Figure 1

Optional Inputs

We can change the solution layout to display a transient format using the key FORMAT by evaluating the formula =PDSOLVE(B8, B2:B6, C8, D8, {0,1}, {0,1}, , {"FORMAT", "TCOL1"}) in array k4:O26. In this format, the locations of the spatial and time points are swapped as shown in Table 3. This permits easy plotting of transient views as shown in Figure 2. Note that we skipped over argument 7, and specified the optional key/value pair in argument 8 using a convenient array constant.

Table 3
kLMNO
4x00.250.751
5tuuuu
60100000
70.0510042.919498341.77830.313101
80.110057.62370039.8721255.069309
90.1510064.942729919.3383113.57766
100.210069.7906132528.3777322.76939
110.2510073.5525723936.584531.45587
120.310076.7066844243.9096839.32101
130.3510079.4382906750.4081146.33273
140.410081.8333584456.1603652.55249
150.4510083.9447940961.2472758.05647
160.510085.8097339965.7444562.92253
170.5510087.4572265469.7200367.22546
180.610088.9122056473.2346271.03141
190.6510090.1982012276.3414574.39453
200.710091.335340779.0874877.36648
210.7510092.341358881.5144279.99204
220.810093.2312405883.659482.31287
230.8510094.0174126885.5556284.36516
240.910094.7117762887.2319986.18001
250.9510095.3250231988.7140687.78445
26110095.8671433790.0240989.20245
Figure 2

We can also request to output the derivative variables in the result using the key NDRVOUT. For example, to include ux in the output, we can evaluate the formula =PDSOLVE(B8, B2:B6, C8, D8, {0,1}, {0,1,2}, , {"NDRVOUT", 1}) in array A10:G32. The results are shown in Table 4 and Figure 3.

You can supply multiple control keys separated by commas using the constant array format as shown, or you can define them in a 2-column array and pass its address or name.

Table 4
ABCDEFG
10t000.50.511
11xuuxuuxuux
1201000100-58.2477100-16.9647
130.050097.09061-58.06899.15264-16.9123
140.10094.19917-57.530198.31051-16.7555
150.150091.34352-56.637197.47881-16.4953
160.20088.54128-55.394896.66268-16.1333
170.250085.80973-53.810895.86714-15.6716
180.30083.16573-51.89595.09712-15.1134
190.350080.62557-49.659294.35736-14.4618
200.40078.20491-47.117393.65242-13.7212
210.450075.91868-44.285192.98665-12.896
220.50073.78095-41.1892.36414-11.9914
230.550071.8049-37.821391.78874-11.0131
240.60070.00271-34.229691.26397-9.96694
250.650068.38546-30.427190.79306-8.85955
260.70066.96312-26.437390.37892-7.69767
270.750065.74445-22.284690.02409-6.48848
280.80064.73694-17.994789.73074-5.23936
290.850063.94682-13.59489.50069-3.95803
300.90063.37894-9.1094689.33534-2.6523
310.950063.03681-4.5688289.23573-1.33025
3210062.92253-1.8E-1289.20245-1.8E-12
Figure 3

The following coupled nonlinear system has known analytical solution for the following configuration:

ut=uxvx+v-1uxx+16x.t-2t-16v-1u-1+10x.e-4x vt=vxx+ux+4u-4+x2-2t-10t.e-4x
Time period t ∈ [0,2]
Spatial range 0 ≤ x ≤ 1
Initial values

ux,0=1

vx,0=1

Left boundary condition

u0,t= 1

v0,t= 1

Right boundary condition

ux1,t=3(1-u1,t)

vx1,t=0.2u1,t-1e4

The exact solution1 is given by:

ux,t=1+10x.t.e-4x vx,t=1+x2t

1Madsen N.K., Sincovec R.F. Software for partial differential equations, in Numerical Methos for Differential Systems, L. Lapidus, W.E. Schiesser eds., Acedemic Press, New York (1976))

We solve this system next with PDSOLVE

Solution

Working with the named variables t, x, u, v, ux, vx, uxx, vxx, we define the input arguments to PDSOLVE as shown in Table 1, including the system equations, left and right boundary conditions formulas, and the initial values for u and v.

Table 1
ABCD
1Variables
2tux
3xvx
4u1uxx
5v1vxx
6EquationsLeft BcRight Bc
7u,t=vx*ux+(v-1)*uxx+(16*x*t-2*t-16*(v-1))*(u-1)+10*x*EXP(-4*x)=u-1=ux-3*(1-u)
8v,t=vxx+ux+4*u-4+x^2-2*t-10*t*EXP(-4*x)=v-1=vx-0.2*(u-1)*EXP(4)

To obtain the solution, we evaluate the formula =PDSOLVE(B7:B8, (B2:B5,D2:D5), C7:C8, D7:D8, {0,1}, {0,1}) in allocated array A10:G32 and obtain the solution shown in Table 2. The numerical results are virtually identical to the analytical solution with shown precision. Snapshots of u and v profiles at different times are plotted in Figure 1.

Excel Tip. We used Excel union operator (Ref1, Ref2, ..), to combine all the system variables (B2:B5,D2:D5) into one reference in argument 2. The union operator preserves the order of the variables which is required. This is equivalent to grouping the named variables in the required order (t, x, u, v, ux, vx, uxx, vxx) in argument 2.

Table 2
ABCDEFG
10t001122
11xuvuvuv
120111111
130.05111.4093661.00251.8187311.005
140.1111.670321.012.3406391.02
150.15111.8232181.02252.6464351.045
160.2111.8986581.042.7973161.08
170.25111.9196991.06252.8393971.125
180.3111.9035831.092.8071661.18
190.35111.8630891.12252.7261791.245
200.4111.8075861.162.6151721.32
210.45111.7438451.20252.487691.405
220.5111.6766761.252.3533531.5
230.55111.6094171.30252.2188351.605
240.6111.5443081.362.0886161.72
250.65111.4827781.42251.9655571.845
260.7111.425671.491.8513411.98
270.75111.3734031.56251.7468062.125
280.8111.3260981.641.6521952.28
290.85111.2836731.72251.5673462.445
300.9111.2459141.811.4918272.62
310.95111.2125221.90251.4250452.805
321111.18315621.3663133
Figure 1

Burgers equation arises in various topics including fluid mechanics in particular.

ut=-uux+v2ux2

We solve this system for the following configuration and compare our numerical results with published exact Fourier solution

Time period t ∈ [0,3]
Spatial range 0 ≤ x ≤ 1
Parameter μ = 0.1 and .01
Initial value ux,0=sinπx
Left boundary condition u0,t=0
Right boundary condition u1,t=0

Solution

Working with named variables t, x, u, ux, uxx, we define the input arguments to PDSOLVE as shown in Table 1, including the system equation, left and right boundary conditions formulas, and the initial value for u.

Table 1
ABCD
1VariablesParameters
2tmu0.1
3x
4u=SIN(PI()*x)
5ux
6uxx
7EquationsLeft BcRight Bc
8du/dt=mu*uxx-u*ux=u=u

Next, we evaluate the array formula =PDSOLVE(B8, B2:B6, C8, D8, {0,1}, {0,0.4,0.6,1,2,3}) in allocated array A10:G32 and obtain the solution shown in Table 2. Note that we have requested to report custom output time points in the interval [0,3] using one of the allowed formats for argument 6. Figure 1 plots snapshot views of the u at various time points.

Table 2
ABCDEFG
10t00.40.6123
11xuuuuuu
1200-1.09849E-19-1.76817E-19-3.38039E-19-6.94334E-19-7.66987E-19
130.050.1564340.0629673680.0489111870.0332394530.0144794940.00591558
140.10.3090170.1256523930.097644220.0663115450.0287536110.011711215
150.150.453990.1877599880.1460094370.099035390.0426124250.017267755
160.20.5877850.2489679880.19379250.1312017810.0558371840.022467765
170.250.7071070.3089094490.2407377050.1625559190.0681966530.027196686
180.30.8090170.3671489790.2865252310.1927762380.0794444820.031344339
190.350.8910070.4231495750.3307389770.2214481390.0893181630.034806865
200.40.9510570.4762246340.3728203570.2480316460.0975402840.037489146
210.450.9876880.525467210.4120017950.2718227820.1038229390.039307725
220.510.5696461980.4472131540.2919109850.1078762310.040194162
230.550.9876880.6070551390.4769537810.3071379370.1094217610.04009872
240.60.9510570.6353033830.4991314960.3160716050.1082116140.038994127
250.650.8910070.6510493140.5108850430.3170179030.104052840.036879198
260.70.8090170.6497271430.5084545770.3081071840.0968359930.033781846
270.750.7071070.6254204240.4872385940.287500070.0865652540.029761188
280.80.5877850.5712366550.4422869950.2537497750.0733854820.024908229
290.850.453990.480741780.3695276470.2063114940.0576007810.019344871
300.90.3090170.3509113180.2678184010.1460940080.0396786380.013220984
310.950.1564340.1860224130.1412221450.0758299490.0202351040.006709534
3211.23E-161.22515E-161.22515E-161.22515E-161.22515E-161.22515E-16
Figure 1

Effect of viscosity μ

We change the value of mu in D2 from 0.1 to 0.01. Figure 2 shows the updated profiles for u.

Figure 1

Comparison with published analytical solution

A Fourier-based solution1 values for Burgers equation for two values of μ are listed in Table 3 along with computed values by PDSOLVE. The results are virtually identical.

1S. Kutluay, A.R. Bahadir, A. Ozdes, Numerical solution of one-dimensional Burgers equation, explicit and exact-explicit finite difference method. Journal of Computational and Applied Mathematics 103 (i 999) 251-261

Table 3
xtu (μ=0.1)
Fourier      PDSOLVE
u (μ=0.01)
Fourier      PDSOLVE
0.250.60.24074    0.2407377050.26896    0.268975372
10.16256    0.1625559190.18819    0.188198472
30.02720    0.0271966860.07511    0.075115705
0.750.60.48721    0.4872385940.76724    0.767275326
10.28747    0.287500070.55605    0.556072119
30.02977    0.0297611880.22481    0.224816515

PDSOLVE implements the method of lines. Spatial discretization is carried out on a uniform mesh using a standard collocation method. The resulting implicit ODE system is integrated by any of the algorithms RADAU5, BDF, or ADAMS with adaptive step control.

BDF
An implicit backward differentiation formula method (DLSODE) suitable for nonlinear stiff and non-stiff systems. (Default algorithm.)
RADAU5
An implicit Runge-Kutta method of order 5 with adaptive step size and error control. suitable for nonlinear stiff problems.
ADAMS
An implicit Adams method (DLSODI) suitable for non-stiff systems.

  • Schiesser W.E (1991). The Numerical Method of Lines, San Diego, CA: Academic Press, 1991.
  • Ascher U M, Mattheij R M M and Russell R D. Numerical Solution of Boundary Value Problems for Ordinary Differential Equations, Prentice Hall, (1988).
  • Ernst Hairer and Gerhard Wanner, Solving Ordinary Differential Equations II: Stiff and Differential-Algebraic Problems (Springer Series in Computational Mathematics), 1996.
  • Alan C. Hindmarsh, ODEPACK, A Systematized Collection of ODE Solvers, in Scientific Computing, R. S. Stepleman et al. (Eds.), North-Holland, Amsterdam, 1983, pp. 55-64.
Question or Comment? Email us:
support @ excel-works.com

ExceLab: Transforming Excel into a Calculus Power House

ExceLab functions and methods are protected by USA Patents 10628634, 10114812, 9892108 and 9286286.

© 2015-2024, ExcelWorks LLC
Boston, USA