我试图解决一个二维传热问题(我是一个MATLAB初学者)。我已经编写了下面的代码,当我运行它时,它不会停止。我试图使用error (err)合并一个收敛条件,但是每当我停止程序时,我总是发现我的错误是150。有人能帮助调整这段代码以获得收敛性检查吗?
(顺便说一句,我的项目是一个3D项目,我只是尝试一个2D案例,然后一旦我开始工作,我就会扩展它)。
%===Solution of the problem of 2D in the bookmarks:Case2a=====
close all;
clear all;
clc;
DX=3; % step size
DY=3;
Lx= 60; %length along x-axis in cmn
Ly=30; %length along y-axis
m=Lx/DX+1; %Number of nodes along x-axis
n=(Ly/DY+1); %Number of nodes along y-axis
n=floor(n);
k=2;
h=500;
T_inf=20;
X=0:DX:Lx;
Y=0:DY:Ly;
T=zeros(m,n);
tol=1;
s=0; %s=2000 could be set as the maximum number of allowed iteration for example
err=1;
T_old=10;
while err >=tol && s<2001
s=s+1;
%--boundary conditions----------------------------------------------------
T(1,:)=160; %west
T(m,:)=100; %east
%===South Boundary "insulation" ==============
for i=2:m-1
T(i,1)=0.25*[2*T(i,2)+T(i-1,1)+T(i+1,1)];
end
%================North Boundary "Convection" ================
for i=2:m-1
T(i,n)=0.5*k/(h*DX+2*k)*[2*T(i,n-1)+T(i-1,n)+T(i+1,n)+2*h*DX*T_inf/k];
end
for i = 2:m-1
for j = 2:n-1
T(i,j)=0.25*(T(i-1,j)+T(i+1,j)+T(i,j-1)+T(i,j+1));
end
end
err=max(max(abs(T-T_old)));
end
%T=rot90(T)发布于 2017-11-26 23:40:32
在计算T之后,您可能应该在循环中将T_old分配给err。
https://stackoverflow.com/questions/47501306
复制相似问题