赞
踩
显式前向欧拉法
源程序:
function [u,x,t] = EF_Euler(A,xf,T,it0,bx0,bxf,M,N)
%解方程 A u_xx = u_t , 0 <= x <= xf, 0 <= t <= T
%初值: u(x,0) = it0(x)
% 边界条件: u(0,t) = bx0(t), u(xf,t) = bxf(t)
% M : x 轴的等分段数
% N : t 轴的等分段数
dx = xf/M; x = [0:M]*dx;
dt = T/N; t = [0:N]'*dt;
for i= 1:M + 1
u(i,1) =it0(x(i));
end
for j = 1:N + 1
u([1 M + 1],j)= [bx0(t(j)); bxf(t(j))];
end
r = A*dt/dx/dx, r1 = 1 - 2*r;
if(r>0.5)
disp('r>0.5,unstability');
end
for j = 1:N
for i = 2:M
u(i,j+1) =r*(u(i + 1,j) + u(i-1,j)) + r1*u(i,j); %(9.2.3)
end
end
u=u';
%-----------------------------
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。