How to obtain convergence of the curve to my boundary condtion?
9 次查看(过去 30 天)
显示 更早的评论
I want a curve in each 'j'th iteration. But, I didn't get convergence of the curve to plot each 'j'th iterations between limit 1 to 0. Because, my boundary condition i.e.
T(1,:)=1;T(end,:)=0
doesn't fit with my code. how to use code for convergence condition?
Further, My data values of each 'j'the iterations are not gradual values along my boundary condition and the data values in 'j' th iteration are increasing only.,
clc; close all; clear all;
ymax=20; m=80; dy=ymax/m; %'i'th row
xmax=1; n=20; dx=xmax/n; %'j'th column
tmax=100; nt=500; dt=tmax/nt;
tol=1e-5; max_difference=1;
%====================INTIALIZATION=================================%
UOLD=zeros(m,n); VOLD=zeros(m,n);
TNEW=0; TOLD=ones(m,n);
A=zeros([1,m]);
B=A;
C=A;
D=A;
T=TOLD;
tic
for j=1:n
for i=1:m
if j>i
C(i)=(dt*VOLD(i,j)/4*dy)-(dt/(2*dy^2));
elseif i>j
A(i)=(-dt*VOLD(i,j)/4*dy)-(dt/(2*dy^2));
elseif i==j
B(i)=1+(dt*UOLD(i,j)/2*dx)+(dt/(dy^2));
end
end
end
for j=2:n
for i=1:m
D(i)=(-dt*UOLD(i,j)*(-TNEW+TOLD(i,j)-TNEW)/2*dx)+(dt/(2*dy^2)*(TOLD(i+1,j)-2*TOLD(i,j)+TNEW))-(dt*VOLD(i,j)/4*dy*(TNEW-TOLD(i+1,j)-TOLD(i,j)));
end
end
T(:,j)=TriDiag(A,B,C,D); %call tridiagonal
dt=0.2+dt;
%T(1,:)=1;T(end,:)=0; % how to use thsi to get perfect curve
Thanks for advance!
0 个评论
回答(1 个)
LeoAiE
2023-4-26
It seems like you are trying to enforce the boundary condition T(1,:) = 1 and T(end,:) = 0 after the solution is computed in each iteration. However, this approach won't necessarily converge to the correct solution.
To incorporate the boundary conditions correctly, you need to modify the system of equations itself. In your case, the boundary conditions should be applied during the construction of the A, B, C, and D matrices.
clc; close all; clear all;
ymax=20; m=80; dy=ymax/m; %'i'th row
xmax=1; n=20; dx=xmax/n; %'j'th column
tmax=100; nt=500; dt=tmax/nt; t=0:dt:tmax; % time at 'j'
tol=1e-2; max_difference(1)=1;
%====================INTIALIZATION=================================%
UOLD=zeros(m,nt); VOLD=zeros(m,nt);
TNEW=0; TOLD=TNEW*ones(m,nt); TWALL=ones(1,length(t));
A=zeros([1,m]);
B=A;
C=A;
D=A;
T=TOLD;
tic
for j=1:nt
for i=1:m
if i == 1 % Top boundary condition
A(1) = 0;
B(1) = 1;
C(1) = 0;
D(1) = 1;
elseif i == m % Bottom boundary condition
A(m) = 0;
B(m) = 1;
C(m) = 0;
D(m) = 0;
elseif j>i
C(i)=(dt*VOLD(i,j)/4*dy)-(dt/(2*dy^2));
elseif i>j
A(i)=(-dt*VOLD(i,j)/4*dy)-(dt/(2*dy^2));
elseif i==j
B(i)=1+(dt*UOLD(i,j)/2*dx)+(dt/(dy^2));
end
end
for j=2:nt
if j==1
for i=1:m
if i==1
D(i)=(-dt*UOLD(i,j)*(-TNEW+TOLD(i,j)-TNEW)/2*dx)+(dt/(2*dy^2)*(TOLD(i+1,j)-2*TOLD(i,j)+TNEW))-(dt*VOLD(i,j)/4*dy*(TNEW-TOLD(i+1,j)-TOLD(i,j)))-(dt/4*dy*VOLD(i,j))-(dt/2*dy^2*TNEW);
elseif i==m
D(i)=(-dt*UOLD(i,j)*(-TNEW+TOLD(i,j)-TNEW)/2*dx)+(dt/(2*dy^2)*(TWALL(j)-2*TOLD(i,j)+TOLD(i-1,j)))-(dt*VOLD(i,j)/4*dy*(TOLD(i-1,j)-TWALL(j)+TOLD(i,j)))-((-dt)/4*dy*VOLD(i,j))-(dt/2*dy^2*TWALL);
else
D(i)=(-dt*UOLD(i,j)*(-TNEW+TOLD(i,j)-TNEW)/2*dx)+(dt/(2*dy^2)*(TOLD(i+1,j)-2*TOLD(i,j)+TOLD(i-1,j)))-(dt*VOLD(i,j)/4*dy*(TOLD(i-1,j)-TOLD(i+1,j)+TOLD(i,j)));
end
end
else
for i=1:m
if i==1
D(i)=(-dt*UOLD(i,j)*(-T(i,j-1)+TOLD(i,j)-TOLD(i,j-1))/2*dx)+(dt/(2*dy^
2 个评论
LeoAiE
2023-4-26
Maybe I have an idea of what you are looking for here. Try this
clc; close all; clear all;
ymax=20; m=80; dy=ymax/m; %'i'th row
xmax=1; n=20; dx=xmax/n; %'j'th column
tmax=100; nt=500; dt=tmax/nt; t=0:dt:tmax; % time at 'j'
tol=1e-2; max_difference(1)=1;
%====================INTIALIZATION=================================%
UOLD=zeros(m,nt); VOLD=zeros(m,nt);
TNEW=0; TOLD=TNEW*ones(m,nt); TWALL=ones(1,length(t));
A=zeros([1,m]);
B=A;
C=A;
D=A;
T=TOLD;
tic
for j=1:nt
for i=1:m
if i == 1 % Top boundary condition
A(1) = 0;
B(1) = 1;
C(1) = 0;
D(1) = TWALL(j);
elseif i == m % Bottom boundary condition
A(m) = 0;
B(m) = 1;
C(m) = 0;
D(m) = TNEW;
elseif j>i
C(i)=(dt*VOLD(i,j)/4*dy)-(dt/(2*dy^2));
elseif i>j
A(i)=(-dt*VOLD(i,j)/4*dy)-(dt/(2*dy^2));
elseif i==j
B(i)=1+(dt*UOLD(i,j)/2*dx)+(dt/(dy^2));
end
end
D(1) = TWALL(j); % Top boundary condition
D(m) = TNEW; % Bottom boundary condition
T(:,j)=TriDiag(A,B,C,D); %call tridiagonal
dt=0.2+dt;
TOLD=T;
max_difference(j) = max(abs(T(:,j)-T(:,j-1))./max(1,abs(T(:,j-1))));
if max_difference(j)<tol
break
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!