(1)迎风格式
function u = peHypbYF(a,dt,n,minx,maxx,M)
format long;
h = (maxx-minx)/(n-1);
if a>0
for j=1:(n+M)
u0(j) = IniU(minx+(j-M-1)*h);
end
else
for j=1:(n+M)
u0(j) = IniU(minx+(j-1)*h);
end
end
u1 = u0;
for k=1:M
if a>0
for i=(k+1):n+M
u1(i) = -(dt/h)*a*(u0(i)-u0(i-1))+u0(i);
end
else
for i=1:n+M-k
u1(i) = -(dt/h)*a*(u0(i+1)-u0(i))+u0(i);
end
end
u0 = u1;
end
x=0.01:0.01:n/100;
u = u1((M+1):(M+n));
plot(x,u,'r');
axis([0 1 -0.5 1.5]);
hold on
y=1.*(x<=0.5)+0.*(x>0.5);
plot(x,y,'g')
title('ó-·???ê?')
format short;
运行结果
>> u=peHypbYF(1,0.005,101,0,1,100)