Professional Documents
Culture Documents
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.
𝑢(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
end
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
subplot(1,2,1)
surf(xvec,tvec,U)
xlabel('x axis')
ylabel('t axis')
s1=sprintf('h_t=%6.4f h_x=%6.4f',ht,hx)
title(s1)
hold on
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
>> L=1;
>> T=0.2;
>> nx=5;
>> nt=10;