(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
el
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
el
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)
(2)Lax-Fridrichs格式
function u = LaxFridrichs(a,dt,n,minx,maxx,M)
format long;
h = (maxx-minx)/(n-1);
for j=1:(n+2*M)
u0(j) = IniU(minx+(j-M-1)*h);
end 简爱第一章读后感
u1 = u0;
工作语言for k=1:M
for i=k+1:n+2*M-k
销售方案模板
u1(i) = -(dt/h)*a*(u0(i+1)-u0(i-1))/2+(u0(i+1)+u0(i-1))/2;
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('Lax-Fridrichs¸ñʽ')
format short;
运行结果
>> u = LaxFridrichs(1,0.005,101,0,1,100)
(3)Lax-a上面两个点Wendroff格式
function u = LaxWendroff(a,dt,n,minx,maxx,M)
团子头format long;
h = (maxx-minx)/(n-1);
for j=1:(n+2*M)
u0(j) = IniU(minx+(j-M-1)*h);
end
u1 = u0;
for k=1:M
for i=k+1:n+2*M-k
u1(i) = (dt/h)^2*a*a*(u0(i+1)-2*u0(i)+u0(i-1))/2- ...
(dt/h)*a*(u0(i+1)-u0(i-1))/2+u0(i);
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('Lax-Wendroff¸ñʽ')
format short
运行结果