2D finite difference method
조회 수: 4 (최근 30일)
이전 댓글 표시
I'm trying to solve for for the node temperatures for a 2d finite difference method problem after a certain number of time interval have passed. I see that it is using the calculated temperatures within the for loop instead of the values from the previous iteration. I don't know how to overcome this to save the values from each iteration seperately until the next loop starts. I feel like i might need to scratch this and start over...? Suggestions?
clear
M = 76;
meshsize=0.2;
m = 1+(0.8/meshsize);
n = 1+(0.4/meshsize);
N=(((1498.6/meshsize^.2)*meshsize)/20); %heat transfer rate varies with y
A1=1-2/M;
A2=1-4/M;
A3=1-22.677/M;
A4=1-((4+2*(N))/M);
A5=1-(10/M);
A6=1-((2.5+(N))/M);
qg=400000*((meshsize^2)/20);
Ts = 60; %Fluid temp
dt=.004;
t = .5;
A=t/dt;
T = zeros(m,n);
%set starting temperature at nodes
for y = 1:m;
for x = 1:n;
T(y,x) = 60; %initial temperature throughout
end
end
for c = 1:A;
T1(1,1) = (1/M)*(T(2,1)+T(1,2)+0.5*qg)+(1-2.5/M)*T(1,1);
for x = 2:n-1;
for y = 2:m-1;
T1(y,1) = (1/M)*(2*T(y,2)+T(y-1,1)+T(y+1,1)+qg)+A2*T(y,1);
T1(1,x) = (1/M)*(2*T(y+1,x)+T(y,x+1)+T(y,x-1)+qg)+A2*T(2,x);
T1(y,x) = (1/M)*(2*T(y+1,x)+2*T(y-1,x)+2*T(y,x+1)+2*T(y,x-1)+2*qg)+A5*(T(y,x));
T1(y,n) = (1/M)*(2*T(y,n-1)+T(y-1,n)+T(y+1,n)+2*N*Ts+qg)+A4*T(y,n);
T1(1,n) = (1/M)*(T(1,n-1)+T(2,n)+N*Ts+.5*qg)+A6*T(1,n);
end
end
end
댓글 수: 1
Torsten
2018년 11월 20일
Use a three-dimensional matrix T1 where the first dimension saves time instants and the last two the spatial coordinate position.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fluid Network Interfaces Library에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!