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 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