I am trying to resolve a 2D heat transfer problem (I am a Matlab starter). I have written the code below, and when I run it it does not stop. I tried to incorporate a convergence condition using the error (err), but whenever I stop the program I always find that my error was 150. Could someone help to adjust this code to get the convergence check. (By the was my project is a 3d project, I am just trying a 2d case then once i get it working I will expand it). Thank you for the help
%===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)
Best Answer