我使用以下MATLAB代码用隐式有限差分法实现沿杆的一维扩散方程。 `
xsize = 10; % Model size, m
xnum = 10; % Number of nodes
xstp = xsize/(xnum-1); % Grid step
tnum = 504; % number of timesteps
kappa = 833.33; % Thermal diffusivity, m^2/s
dt = 300; % Timestep
x = 0:xstp:xsize; %Creating vector for nodal point positions
tlbc = sin(linspace(0.1,2.9,tnum)); % left boundary condition
%Define initial temperature profile
tback = 0; % background temperature, K
for i=1:1:xnum
% Background profile
t0imp(i) = tback; % profile for implicit solving
end
% Time cycle
timesum=0; % Elapsed time
for t=1:1:tnum
% Matrix of coefficients initialization for implicit solving
L = sparse(xnum,xnum);
% Vector of right part initialization for implicit solving
R = zeros(xnum,1);
% Implicit solving of 1D temperature equation: dT/dt=kappa*d2T/dx2
% Composing matrix of coefficients L()
% and vector (column) of right parts R()
% First point: T=tback
L(1,1) = 1;
R(1,1) = tlbc(t);
% Intermediate points
for i=2:1:xnum-1
% dT/dt=kappa*d2T/dx2
% Tnew(i)/dt-kappa*(Tnew(i-1)-2*Tnew(i)+Tnew(i+1))/dx^2=Told(i)/dt
L(i,i-1) = -kappa/xstp^2;
L(i,i) = 1/dt+2*kappa/xstp^2;
L(i,i+1) = -kappa/xstp^2;
R(i,1) = t0imp(i)/dt;
end
% Last point:T=tback
L(xnum,xnum) = 1;
R(xnum,1) = tback;
% Obtaining solution for implicit temperature profile
t1imp = L\R;
end `
我想将右边界条件改为无限边界条件,以便10 m边界的存在对10 m域内的热流和温度流没有影响,好像在10 m处没有边界。
答案 0 :(得分:0)
如果您有远离边界的局部现象,那么我建议您使用非均匀网格进行x空间离散化。网格应该在感兴趣的区域中具有更多的点。然后,您可以选择较大的xsize,但保持网格点的数量合理。
非均匀网格实现起来比较棘手(对于1-d来说不是那么糟糕)但幸运的是Matlab有pdepe来解决类型的非均匀方程
\开始{}方程 c \ left(x,t,u,\ frac {\ partial u} {\ partial x} \ right)\ frac {\ partial u} {\ partial t} = x ^ { - m} \ frac {\ partial} {\ partial t} \ left(x ^ mf \ left(x,t,u,\ frac {\ partial u} {\ partial x} \ right)\ right)+ S \ left(x,t,u,\ frac {\ partial u} {\ partial x} \ right) \ {端方程}
使用用户定义的网格物体。你可以在这里阅读更多关于pdepe的信息
https://www.mathworks.com/help/matlab/ref/pdepe.html
他们也解决了你感兴趣的等式。