How can i perform an ADI method on 2d heat equation
17 次查看(过去 30 天)
显示 更早的评论
im trying to slve this equation : 𝜕𝑇 𝜕𝑡 = 𝜕 2𝑇 𝜕𝑥 2 + 𝜕 2𝑇 𝜕𝑦 2
𝑇(𝑥, 𝑦, 0) = 0
𝑇(0, 𝑦,𝑡) = 0
𝑇(1, 𝑦,𝑡) = 0
𝑇(𝑥, 0,𝑡) = 0
(𝑥, 1,𝑡) = 100 sin 𝜋x
so for the first part which is in x direction i did the following :
c
lose all;
clc;
dt = 0.001; %time step
dx = 0.1; %step in x direction
t = 0:dt:15; %time interval (changable due to your desighn)
x = 0:dx:1; %x-axis interval (changable due to your desighn)
lamda=dt/(2*dx^2);
a=(1+2*lamda)*ones(1,13);%define matrix A
A=diag(a); %make matrix a diagonal one
N = length(x)+2; %interval (changable due to your desighn)
for i=1:N-1
A(i+1,i)=-lamda;
A(i,i+1)=-lamda;
end
A(1,1)=1+2*lamda;
A(1,2)=-lamda;
A(13,12)=-lamda;
A(13,13)=1+2*lamda;
T=[]; %Dynamic size array
a2=lamda*ones(1,13);
A2=diag(a);
for j=1:N-3
A2(j+3,j)=(1-2*lamda);
A2(j,j+3)=(1-2*lamda);
end
T(:,:,:) = zeros(length(t),length(y)+2,length(x)+2); %define initial condition
Tstar=zeros(length(x),length(y));
Tall=zeros(length(x),length(y));
for k=2:length(t)
for j=2:length(x)-1
fx=(l-2*lamda)*T(:,j,k-1)+lamda*T(:,j-1,k-1)+lamda*T(:,j+1,k-1);
fx(1)=0;
fx(end)=0;
Tstar(j,:)=(A\fx)';
end
for i=2:length(y)-1
fy=(1-2*lamda)*Tstar(i,:)+lamda*Tstar(i-1,:)+lamda*Tstar(i+1,:);
fy(:,1)=0;
fy(:,end)=100*sin(pi*x(i));
end
Tall(:,j)=A\fy;
T(:,:,k)=Tall(:,:);
end
i've used imaginary node to solve the proplem , also i did the following analysis for the code :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/599145/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/599150/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/599155/image.png)
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!