0
我试图解决1D中的瞬态热方程,并比较分析解和数值解。这些解决方案具有相同的趋势但非常不同,即使其明显不应该是相对误差也是零。我不知道我是否已经正确解决了PDE。 (pde是du/dt = d^2u/dx^2)并且bcs是u(0,t)= 1,u(100,t)= 0,u(x,0)= 0。有人可以看看我的代码吗?Matlab PDE求解器问题
function he
m = 0;
x = linspace(0,100,500);
t = linspace(0,1000,500);
sol = pdepe(m,@hepde,@heic,@hebc,x,t);
u = sol(:,:,1);
y = erfc(x./(2*(t.^0.5)));
r=(y-u(70,:))/y;
figure;
plot(x,u(50,:),'.',x,u(150,:),'.',x,u(250,:),'.',x,u(end,:),'.',x,y,'.');
title('Numerical Solutions at different times.');
legend('t=100','t=300','t=500','t=700','y ana',0);
xlabel('Distance x');
ylabel('u(x,t)');
figure;
plot(x,r);
title('error in numerical and analytical solution');
legend('error',0);
xlabel('Distance x');
ylabel('error');
% --------------------------------------------------------------------------
function [c,f,s] = hepde(x,t,u,DuDx)
c = 1;
f = DuDx;
s = 0;
% --------------------------------------------------------------------------
function u0 = heic(x)
u0 = 0;
% --------------------------------------------------------------------------
function [pl,ql,pr,qr] = hebc(xl,ul,xr,ur,t)
pl = ul-1;
ql = 0;
pr = ur;
qr = 0;
太感谢你了大卫,我得到了解决,现在!!!! – 2014-09-25 03:01:13