You are on page 1of 4

𝜕𝑢 𝜕2 𝑢

Take the heat equation: 𝜕𝑡 = 𝐷 𝜕𝑥 2 (1)

To investigate the stability of the given partial differential equation (PDE) with
the specified initial and boundary conditions, let's analyze the behavior of the
solution of the general heat equation (1) over time.

To assess stability, we can employ the Von Neumann stability analysis by


considering a discretization scheme, such as the Finite Definite FD scheme:
𝑈(𝑛 + 1, 𝑗) − 𝑈(𝑛, 𝑗) 𝐷[𝑈(𝑛, 𝑗 + 1) − 2𝑈(𝑛, 𝑗) + 𝑈(𝑛, 𝑗 − 1) ]
=
∆𝑡 (∆𝑥)2
(explicit Euler) (central)

𝑈(𝑛 + 1, 𝑗) = 𝑈(𝑛, 𝑗) + 𝑟([𝑈(𝑛, 𝑗 + 1) − 2𝑈(𝑛, 𝑗) + 𝑈(𝑛, 𝑗 − 1) ])


𝐷∆𝑡
𝑟=
(∆𝑥)2

By assuming a solution of the form:


2
𝑈(𝑛, 𝑗) = 𝑒 −𝐷𝑘 𝑡 𝑒 𝑖𝑘𝑥
2𝑡
𝑒 −𝐷𝑘 = 𝐺(𝑘) 𝑔𝑟𝑜𝑤𝑡ℎ 𝑓𝑎𝑐𝑡𝑜𝑟 𝑛𝑜 𝑔𝑟𝑜𝑤𝑡ℎ 𝑖𝑓 |𝐺(𝑘)| ≤ 1 ∀k

We insert 𝑢(𝑥, 𝑡𝑛 ) = 𝑒 𝑖𝑘𝑥 into the discretized equation:

𝑈(𝑛 + 1, 𝑗) = 𝑒 𝑖𝑘∆𝑥𝑗 + 𝑟(𝑒 𝑖𝑘∆𝑥(𝑗+1) − 2 𝑒 𝑖𝑘∆𝑥𝑗 + 𝑒 𝑖𝑘∆𝑥(𝑗−1) )


= 𝑒 𝑖𝑘∆𝑥𝑗 (1 + 𝑟(𝑒 𝑖𝑘∆𝑥 + 𝑒 −𝑖𝑘∆𝑥 − 2)) = 𝐺(𝑘)𝑒 𝑖𝑘∆𝑥𝑗
𝐺𝑟𝑜𝑤𝑡ℎ 𝑟𝑎𝑡𝑒 𝑓𝑎𝑐𝑡𝑜𝑟 𝐺(𝑘) = 1 − 2𝑟(1 − cos(𝑘∆𝑥))
𝐹𝐷 𝑠𝑐ℎ𝑒𝑚𝑒 𝑖𝑠 𝑠𝑡𝑎𝑏𝑙𝑒 𝑖𝑓 |𝐺(𝑘)| ≤ 1 ∀k
−1 < cos(𝑘∆𝑥) < 1
1 − 4𝑟 < 1 − 2𝑟(1 − cos(𝑘∆𝑥)) < 1
𝑖𝑓 1 − 4𝑟 ≥ −1 𝑠𝑡𝑎𝑏𝑙𝑒
1
𝑤𝑒 𝑐𝑎𝑛 𝑤𝑟𝑖𝑡𝑒 𝑖𝑓 𝑟 ≤ 𝑠𝑡𝑎𝑏𝑙𝑒
2
in our case D=1

If we choose ∆𝑥 & ∆𝑡 such that


𝐷∆𝑡 1
𝑟= 2
≤ 𝑤𝑒 𝑔𝑒𝑡 𝑠𝑡𝑎𝑏𝑙𝑒 𝑐𝑎𝑠𝑒
(∆𝑥) 2
1
𝑙𝑒𝑡 ∆𝑡 = 0.5 & ∆𝑥 = 1 𝑡ℎ𝑒𝑛 𝑟 = 𝑠𝑡𝑎𝑏𝑙𝑒
2
∆𝑥 = 𝐿/𝑛𝑥
∆𝑡 = 𝑇/𝑛𝑡
𝜕𝑢 𝜕2 𝑢
Setting D=1 in (1) we get 𝜕𝑡
= 𝜕𝑥 2 (2) We take the initial condition 𝑢(𝑥, 0) =
𝑠𝑖𝑛(𝜋𝑥) and the boundary conditions 𝑢(0, 𝑡) = 𝑢(1, 𝑡) = 0 𝑤ℎ𝑒𝑟𝑒 𝑡 >
0 𝑎𝑛𝑑 𝑥 ∈ [0, 1].
2
The exact solution is 𝑢(𝑥, 𝑡) = 𝑒 −𝜋 𝑡 sin (𝜋𝑥)

Set T=0.2 L=1 𝑛𝑥 = 5 𝑛𝑡 = 10 ℎ𝑥 = 0.2 ℎ𝑡 = 0.02


25
𝑟 = 0.2 ∗ = 0.5 𝑠𝑡𝑎𝑏𝑙𝑒
10
If we take a time t=0.02 then

𝑢(0,0.2) = 0
2
𝑢(0.2,0.2) = 𝑒 −𝜋 ∗0.2 sin(𝜋 ∗ 0.2) = 0.08164991544
2
𝑢(0.4,0.2) = 𝑒 −𝜋 ∗0.2 sin(𝜋 ∗ 0.4) = 0.13211233836
2
𝑢(0.6,0.2) = 𝑒 −𝜋 ∗0.2 sin(𝜋 ∗ 0.6) = 0.13211233836
2 ∗0.2
𝑢(0.8,0.2) = 𝑒 −𝜋 sin(𝜋 ∗ 0.8) = 0.08164991544
2 ∗0.2
𝑢(1,0.2) = 𝑒 −𝜋 sin(𝜋 ∗ 0.4) = 0

MATLAB

function U = Heat1(a,f,u0,g1,g2,L,T,nx,nt)

nx1=nx+1;

hx=L/nx;

nt1=nt+1;

ht=T/nt;

r=a*ht/(hx*hx)

r1=1-2*r;

%stability test

if r>0.5

disp('the ratio is too big; the scheme is unstable')

end

%generate the grid point vectors

xvec=hx*(0:nx);

tvec=ht*(0:nt);

U=zeros(nt1,nx1);
U(1,:)=feval(u0,xvec(:)');

U(2,nt1,1)=feval(g1,(1:nt)*ht);

U(2,nt1,nx1)=feval(g2,(1:nt)*ht);

for k=1:nt

U(k+1,2:nx)=r*(U(k,1:nx1)+U(k,3:nx+1))+r1*U(k,2:nx)+ht*feval(f,xvec(2:nx),tve
c(k));

end

%plot the numerical solution

subplot(1,2,1)

surf(xvec,tvec,U)

xlabel('x axis')

ylabel('t axis')

zlabel('the numerical solution')

s1=sprintf('h_t=%6.4f h_x=%6.4f',ht,hx)

title(s1)

hold on

%plot the solution error

Err=exp(-pi*pi*tvec)*sin(pi*xvec)-U;

subplot(1,2,2)

surf(xvec,tvec,Err)

xlabel('x axis')

ylabel('t axis')

zlabel('the error')

title(s1)

now to summon the function with input values we write into MATLAB

>> a = 1; % Heat equation coefficient

>> f = @(x, t) 0; % source term function


>> u0 = @(x) sin(pi*x);% initial condition function

>> g1 = @(t) 0; % boundary condition at x = 0

>> g2 = @(t) 0; % boundary condition at x = L

>> L=1;

>> T=0.2;

>> nx=5;

>> nt=10;

>> U = Heat2(a, f, u0, g1, g2, L, T, nx, nt);

You might also like