首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有限差分

有限差分
EN

Stack Overflow用户
提问于 2017-11-26 21:41:44
回答 1查看 74关注 0票数 1

我试图解决一个二维传热问题(我是一个MATLAB初学者)。我已经编写了下面的代码,当我运行它时,它不会停止。我试图使用error (err)合并一个收敛条件,但是每当我停止程序时,我总是发现我的错误是150。有人能帮助调整这段代码以获得收敛性检查吗?

(顺便说一句,我的项目是一个3D项目,我只是尝试一个2D案例,然后一旦我开始工作,我就会扩展它)。

代码语言:javascript
复制
%===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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-26 23:40:32

在计算T之后,您可能应该在循环中将T_old分配给err

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47501306

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档