Problem with plotting 1D heat diffusion using FTCS

3 views (last 30 days)
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 Comment
Torsten
Torsten on 9 Mar 2024
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 ?

Sign in to comment.

Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!