MATLAB:使用 pdepe 对抛物线椭圆系统进行不正确的计算

计算科学 pde matlab
2021-12-17 08:30:20

我发现 MATLAB 使用 pdepe 函数错误地求解了一维抛物线椭圆系统。这是一个系统: 边界条件: 初始条件: 0。MATLAB 文档告知 pdepe 可以解决此类系统。

ut=uxx+2,
0=vxx+u.
(ux+u)|x=0=2t,(ux+u)|x=1=2t,
(vx+v)|x=0=0,(vx+v)|x=1=0.
u|t=0=0,v|t=0=0.

源代码:

function a

tt = 1;

m = 0;
x = linspace(0,1,100);
t = linspace(0,tt,100);

sol = pdepe(m,@apde,@aic,@abc,x,t);
u1 = sol(:,:,1);
u2 = sol(:,:,2);

figure;
surf(x,t,u1);
title('u1(x,t)');
xlabel('Distance x');
ylabel('Time t');
shading interp
colorbar
set(gca,'YDir','reverse');

figure;
surf(x,t,u2);
title('u2(x,t)');
xlabel('Distance x');
ylabel('Time t');
shading interp
colorbar
set(gca,'YDir','reverse');

figure
plot(x,u1(end,:))
title('u1 at t = tt')
xlabel('Distance x')
ylabel('u1(x,tt)')

figure
plot(x,u2(end,:))
title('u2 at t = tt')
xlabel('Distance x')
ylabel('u2(x,tt)')

figure
plot(x,tt*(1+x-x.^2))
title('TRUE u2 at t = tt')
xlabel('Distance x')
ylabel('u2(x,tt)')

% --------------------------------------------------------------

function [c,f,s] = apde(x,t,u,DuDx)
c = [1; 0];                                 
f = [1; 1] .* DuDx;                  
s = [2; u(1)];

% --------------------------------------------------------------

function u0 = aic(x)
u0 = [0; 0];                                

% --------------------------------------------------------------

function [pl,ql,pr,qr] = abc(xl,ul,xr,ur,t)
pl = [ul(1)-2*t; ul(2)];                              
ql = [-1; -1];                                 
pr = [ur(1)-2*t; ur(2)];                           
qr = [1; 1];              

精确解:

u(x,t)=2t,v(x,t)=t(1+xx2).

MATLAB 正确计算时的精确解uvt=1在 $t = 1$ 时 $v$ 的精确解

MATLAB 计算的近似解: MATLAB 计算的近似解

这个函数甚至不满足边界条件。

v(x,t)图:

$v(x,t)$ 图

让我们用抛物线方程替换我们的椭圆方程,即使用向量

c = [1; 1e-100];

代替

c = [1; 0];

这意味着我们使用等式

10100vt=vxx+u

现在 MATLAB 计算出一个正确的解:

解决方案

因此,此示例表明 MATLAB 不正确地求解具有 Robin 边界条件的抛物线椭圆系统。

如果我们使用狄利克雷边界条件,则解是正确的。

我的推理正确吗?

2个回答

最新版本的 Mathematica 很好地解决了这个问题:

Clear[u,v,nx,eqn1,eqn2,ic1,ic2,vars,eqn1,eqn2,ic1,ic2,vars,sol,PDEsol,order,npts];
npts = 100; order=12; 
nx = Range[0,1,1/(npts-1)];
{ddx,d2dx2} = Map[NDSolve`FiniteDifferenceDerivative[Derivative[#],nx, "DifferenceOrder" -> order]["DifferentiationMatrix"]&,{1,2}] ;
u = Array[u$[#][t]&,npts]; v = Array[v$[#][t]&,npts];

eqn1=Thread[D[u,t]==d2dx2.u+2];
eqn2 = Thread[d2dx2.v+ u==0];

eqn1[[1]]=u[[1]]==ddx[[1]].u+2t;
eqn1[[-1]]=u[[-1]]==2t-ddx[[-1]].u;
eqn2[[1]]=v[[1]]==ddx[[1]].v;
eqn2[[-1]]=v[[-1]]==-ddx[[-1]].v;

ic1=Thread[u==0]/.t->0;
ic2=Thread[v==0]/.t->0;

vars = Flatten[{u, v}] /. x__[t] :> x ; 
PDEsol = First[NDSolve[{eqn1, eqn2, ic1, ic2}, vars, {t, 0, 30}]];
time = Flatten@First[vars[[1]] /. PDEsol];
{usol, vsol} = 
  Flatten[Table[
      Transpose[{nx, ConstantArray[ti, npts], # /. PDEsol}] /. 
       t -> ti, {ti, time[[1]], time[[2]], 0.1}], 1] & /@ {u, v};



  GraphicsRow[ ListPlot3D[#, PlotRange -> All, PlotTheme -> "Classic", 
    Mesh -> {50, 50}, Lighting -> "Neutral"] & /@ {usol, vsol}, 
 ImageSize -> 800]

在此处输入图像描述

不,您没有更改边界条件,边界条件仍然是 Robin 类型。你改变的是抛物线和使用相同边界条件的 DE。事实上,看到这一点令人惊讶。虽然推理不正确。