This notebook presents an example of the heat equation with mixed boundary conditions. This example was worked on in the classroom of the postgraduate mathematics program of the Hellenic Open University, in which I am a student.
Expansion of the function
f(x)2x-1
with respect to the eigenfunctions of the Sturm-Liouville problem
′′
X
+λX0
′
X
(0)X(4)0
In[]:=
Clear["Global`*"]
In[]:=
FPS[x_,N_]:=FullSimplify
N
∑
n=1
c[n]*X[n,x]
In[]:=
X[n_,x_]=
1
2
Cos
(2n-1)*Pi*x
8

Out[]=
Cos
1
8
(-1+2n)πx
2
In[]:=
f[x_]=2*x-1
Out[]=
-1+2x
Notice that the function does not satisfy the boundary conditions of the problem
In[]:=
c[n_]=Simplify
4
∫
0
f[x]*X[n,x]x,n∈Integers
Out[]=
-
4
2
(16+7
n
(-1)
(-1+2n)π)
2
(π-2nπ)
We are testing an expansion of 20 terms
​
In[]:=
FS[x_]=FPS[x,20];
In[]:=
pFS=Plot[FS[x],{x,0,4},PlotStyle{Red,Thick,Dashed},PlotRangeAll]
Out[]=
1
2
3
4
2
4
6
8
In[]:=
s=Plot[f[x],{x,0,4},PlotRangeAll]
Out[]=
1
2
3
4
2
4
6
In[]:=
Show[pFS,s]
Out[]=
1
2
3
4
2
4
6
8
Now, we are going to solve the Heat-equation using the above mixed boundary conditions
​
In[]:=
Clear["Global`*"]
We define the eigenvalues
In[]:=
λ[n_]=
(2*n-1)*π
8
^2
Out[]=
1
64
2
(-1+2n)
2
π
We define the eigenfunctions
In[]:=
X[n_,x_]=Cos
(2n-1)*Pi*x
8

Out[]=
Cos
1
8
(-1+2n)πx
Norms of Eigenfunctions
In[]:=
Norma[n_]=SimplifySqrt
4
∫
0
X[n,x]^2x,n∈Integers
Out[]=
2
Normalized eigenfunctions
In[]:=
Y[n_,x_]=X[n,x]/Norma[n]
Out[]=
Cos
1
8
(-1+2n)πx
2
In[]:=
N
4
∫
0
Y[12,x]*Y[12,x]x
Out[]=
1.
Fourier series coefficients
In[]:=
a[n_]=Simplify
4
∫
0
f[x]*Y[n,x]x,n∈Integers
Out[]=
4
∫
0
Cos
1
8
(-1+2n)πxf[x]
2
x
Partial Fourier series sum for the solution of the heat equation
In[]:=
U[x_,t_,N_]:=
N
∑
n=1
a[n]*Exp[-λ[n]*t]*Y[n,x]
Now we define the initial condition
In[]:=
f[x_]=Cos[Pi*x/8]^4
Out[]=
4
Cos
πx
8

Partial sum of solution series for a finite number of terms
In[]:=
u[x_,t_]=U[x,t,10]
Out[]=
32
-
2
π
t
64

Cos
πx
8

15π
+
32
-
9
2
π
t
64

Cos
3πx
8

35π
+
32
-
25
2
π
t
64

Cos
5πx
8

315π
-
32
-
49
2
π
t
64

Cos
7πx
8

3465π
+
32
-
81
2
π
t
64

Cos
9πx
8

15015π
-
32
-
121
2
π
t
64

Cos
11πx
8

45045π
+
32
-
169
2
π
t
64

Cos
13πx
8

109395π
-
32
-
225
2
π
t
64

Cos
15πx
8

230945π
+
32
-
289
2
π
t
64

Cos
17πx
8

440895π
-
32
-
361
2
π
t
64

Cos
19πx
8

780045π
Now we are going to create the graphs and we will compare them with the numerical solution
In[]:=
fig1=Plot3D[u[x,t],{t,0,30},{x,0,4},PlotRangeAll,ColorFunction"BlueGreenYellow"]
Out[]=
In[]:=
solution=V/.First[NDSolve[
∂
t
V[x,t]
∂
{x,2}
V[x,t],V[x,0]f[x],K[0,t]0,V[4,t]0,{V},{t,0,30},{x,0,4},MaxStepSize10000,MaxSteps10000]]
NDSolve
:Warning: an insufficient number of boundary conditions have been specified for the direction of independent variable x. Artificial boundary effects may be present in the solution.
Out[]=
InterpolatingFunction
Domain: {{0.,4.},{0.,30.}}
Output: scalar


CITE THIS NOTEBOOK

Heat equation problem with mixed boundary conditions​
by Athanasios Paraskevopoulos​
Wolfram Community, STAFF PICKS, June 27, 2023
​https://community.wolfram.com/groups/-/m/t/2943996