WOLFRAM NOTEBOOK

Separation of Variables

For Laplace’s equation on the square

A semi-general problem

Suppose we wish to solve Laplace’s equation
Δu=0
on the unit square subject to
u(0,y)=0
,
u(1,y)=0
,
u(x,0)=f(x)
, and
u(x,1)=g(x)
. Setting
u(x,y)=X(x)Y(y)
and separating variables, we get two ordinary ODEs
X
=-λX,X(0)=0,X(1)=0
and
Y
=λY,Y(0)=f(x),Y(1)=g(x).
The
x
equation is familiar and has eigenvalues
λ
n
=
2
n
2
π
with corresponding eigenfunctions
X
n
(x)=sin(nπx)
.
The
y
equation then becomes
Y
=
2
n
2
π
Y
, which has general solution
Y(y)=
c
n
-nπy
+
d
n
nπy
. The solution to the problem thus has the form
u(x,y)=
n=1
(
c
n
-nπy
+
d
n
nπy
)sin(nπx).
Any function of this form is guaranteed to satisfy Laplace’s equation together with the zero boundary conditions on the left and right side. To satisfy the remaining boundary conditions, we need to choose
c
n
and
d
n
such that
u(x,0)=
n=1
(
c
n
+
d
n
)sin(nπx)=f(x)
and
u(x,1)=
n=1
(
c
n
-nπ
+
d
n
nπ
)sin(nπx)=g(x).
Put another way,
c
n
+
d
n
must be the Fourier sine coefficients of
f
and
c
n
-nπ
+
d
n
nπ
must be the Fourier sine coefficients of
g
. If we let
a
n
denote the Fourier sine coefficients of
f
and we let
b
n
denote the Fourier sine coefficients of
g
, this leads to the following linear system.
In[]:=
Clear[a,b,c,d];Solve[{
c
n
+
d
n
a
n
,
c
n
-nπ
+
d
n
nπ
b
n
},{
c
n
,
d
n
}]
Out[]=
c
n
nπ
(
nπ
a
n
-
b
n
)
-1+
2nπ
,
d
n
-
a
n
+
nπ
b
n
-1+
2nπ

Example

Lets try to illustrate the solution for the specific case
f(x)=
3
x(1-x)
and
g(x)=
3
x
(1-x)
.
In[]:=
f[x_]=4x
3
(1-x)
;g[x_]=4
3
x
(1-x);Plot[{f[x],g[x]},{x,0,1}]
Out[]=
Here are the Fourier coefficients.
In[]:=
$Assumptions={Element[n,Integers],n>0};a[n_]=2
1
0
f[x]*Sin[n*Pi*x]xb[n_]=2
1
0
g[x]*Sin[n*Pi*x]x
Out[]=
48(-4+4
n
(-1)
+
2
n
2
π
)
5
n
5
π
Out[]=
-
48(4-4
n
(-1)
+
n
(-1)
2
n
2
π
)
5
n
5
π
Thus, here are the
c
n
s and
d
n
s.
In[]:=
Clear[c,d];{c[n_],d[n_]}={c[n],d[n]}/.First[Solve[{c[n]+d[n]a[n],c[n]Exp[-n*Pi]+d[n]Exp[n*Pi]b[n]},{c[n],d[n]}]]
Out[]=
1
5
n
5
π
-192+192
n
(-1)
+48
2
n
2
π
-
1
-
5
n
5
π
+
2nπ
5
n
5
π
5
n
5
π
(192-192
n
(-1)
-192
nπ
+192
n
(-1)
nπ
-48
2
n
2
π
-48
n
(-1)
nπ
2
n
2
π
),(192-192
n
(-1)
-192
nπ
+192
n
(-1)
nπ
-48
2
n
2
π
-48
n
(-1)
nπ
2
n
2
π
)(-
5
n
5
π
+
2nπ
5
n
5
π
)
With those coefficients in hand, we can define a high-order approximation to the solution.
In[]:=
u[x_,y_]=
50
n=1
(c[n]Exp[-n*Pi*y]+d[n]Exp[n*Pi*y])Sin[n*Pi*x];
OK, let’s check it out.
In[]:=
Plot3D[u[x,y],{x,0,1},{y,0,1},WorkingPrecision20,BoundaryStyleThick,ColorFunction"TemperatureMap",PlotPoints50,MeshFunctions{#3&}]
Out[]=
Wolfram Cloud

You are using a browser not supported by the Wolfram Cloud

Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.


I understand and wish to continue anyway »

You are using a browser not supported by the Wolfram Cloud. Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.