Matlab:1D无环数值偏微分方程

Matlab:1D无环数值偏微分方程,matlab,numerical-methods,Matlab,Numerical Methods,所以,目前我正试图找到伯杰方程的数值解,$u_t+u∗u_x=0$。该方程的数值解为: $u^{n+1}\u j=u_n^j−\分形{Δx}{Δt}u^n_j(u^n_j−u^n{j−1})$ 我在Matlab上编写了计算这个的代码。如您所见,代码中只有一个for循环。然而,我的u矩阵非常大,算法变得很慢。有没有一种方法可以让我完全不用循环。我正在考虑使用命令cumsum,但我不知道如何将其集成到我的程序中。请看我的密码。谢谢 dx = 0.9; dt = 0.9; tf = 10; l = 1

所以,目前我正试图找到伯杰方程的数值解,$u_t+u∗u_x=0$。该方程的数值解为:

$u^{n+1}\u j=u_n^j−\分形{Δx}{Δt}u^n_j(u^n_j−u^n{j−1})$ 我在Matlab上编写了计算这个的代码。如您所见,代码中只有一个for循环。然而,我的u矩阵非常大,算法变得很慢。有没有一种方法可以让我完全不用循环。我正在考虑使用命令cumsum,但我不知道如何将其集成到我的程序中。请看我的密码。谢谢

dx = 0.9;
dt = 0.9;
tf = 10;
l = 10;
xstep = [-1:dx:l];
tstep = [0:dt:tf];
uinit = zeros(length(tstep),length(xstep));


%%Setting Initial and Boundary Conditions
bc.left = @(t) 2;

bc.right = @(t) -1;

ic = @(x) ...
    2*(x<=0) ...
    -1*(x>0);

uinit(1, :) = ic(xstep);
uinit(:, 1) = bc.left(tstep);
uinit(:, end) = bc.right(tstep);


%% Numerical method part

for c=1:(length(tstep)-1) 
   uinit(2:end -1, c+1) = uinit(2:end -1, c) - dx/dt*(uinit(2:end -1, c).*(uinit(2:end-1, c) - uinit(1:end-2, c)));

end

surf(xstep,tstep,uinit)
dx=0.9;
dt=0.9;
tf=10;
l=10;
xstep=[-1:dx:l];
tstep=[0:dt:tf];
uinit=零(长度(tstep)、长度(xstep));
%%设置初始和边界条件
bc.left=@(t)2;
bc.right=@(t)-1;
ic=@(x)。。。
2*(x0);
uinit(1,:)=ic(xstep);
uinit(:,1)=前左(t步);
uinit(:,end)=右前(t步);
%%数值方法部分
对于c=1:(长度(t步)-1)
uinit(2:end-1,c+1)=uinit(2:end-1,c)-dx/dt*(uinit(2:end-1,c)。*(uinit(2:end-1,c)-uinit(1:end-2,c));
终止
冲浪(xstep、tstep、uinit)

因为u_t依赖于u_(t-1),所以我认为您无法将其并行化。好的,我只是想知道谢谢