Problem with plotting 1D heat diffusion using FTCS

2 ビュー (過去 30 日間)
Giancarlo
Giancarlo 2024 年 3 月 9 日
コメント済み: Torsten 2024 年 3 月 9 日
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 Center および File ExchangeApp Building についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by