Problem with plotting 1D heat diffusion using FTCS

17 次查看(过去 30 天)
Hello, I have this issue with the plot where there is a sudden spike at the temperature near x and t are 0. I can't seem to find the problem with the code. The initial temperature is T(x,0) = x, and the ends of a 1m wire is insulated.
%FTCS march 9
clc;
clear;
c = 1; %alpha, thermal constant
L = 1; %wire length
T = 0.3; %total time
Nt = 6500; %time steps
Dt = T/Nt;
Nx = 100; %space steps
Dx = L/Nx;
b = c*Dt/(Dx*Dx); %must not exceed 1/2
fprintf ('b = %.2f \n', b);
b = 0.46
%Initial conditions
for i=1:Nx+1
x(i) = (i-1)*Dx;
u(i,1) = x(i);
end
%boundary Conditions
for k=1:Nt+1
u(1,k)= 0;
u(end,k)=0;
t(k)= (k-1)*Dt;
end
%FTCS
for k=1:Nt
for i=2:Nx
u(i,k+1) = u(i,k) + b.*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
end
end
mesh(t,x,u)
title ('Plot of time and space')
xlabel('t')
ylabel('x')
zlabel('u')
  1 个评论
Torsten
Torsten 2024-3-9
If you start with
u(i,1) = x(i);
and set
u(1,k)= 0;
u(end,k)=0;
as boundary condition, there will be a discontinuity at x = 1.
Is it that what you mean ?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

产品


版本

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by