Matlab program with the explicit Lax method

该博客通过Matlab程序演示了使用Lax方法解决一维输运方程的过程,探讨了不同时间步长Nt对稳定性的影响。当Nt=300时,b=0.5,处于稳定与不稳定的临界状态;Nt=400时,系统更稳定;而Nt=290时,b>0.5,系统变得不稳定。实验展示了数值解如何随时间演进,并突出了时间步长选择的重要性。
摘要由CSDN通过智能技术生成

https://www.youtube.com/watch?v=ONDp4Rdj0OY 

Matlab program with the explicit Lax method for the advection equation 

%Square-wave test for the lax method to solve the advection equation
clear;

%Parameters needed to Implement the advection 
Lmax = 1.0; % Maxinum length
Tmax = 1.;  % Maximum time
c = 1.0;    % Advection velocity

%Parameters needed to Implement the Lax Method
Nt = 300;   % Number of time steps
Dt = Tmax / Nt;  % Time Step
Nx = 300;   % Number of space steps
Dx = Lmax / Nx;  %Space step
b = c * Dt/(2.*Dx); % beta parameter in the finite-difference imp

%Remember that the lax method is stable for b =< 1/2
%But it gets diffussed unless abs(b) = 1/2

%Initial Condition

Nfront = round(Nx / 2); % Square wave

for i = 1:(Nx + 1)
    if i < Nfront 
        u(i,1) = 1.;
    else
        u(i,1) = 0.;
    end
    x(i) = (i-1)*Dx;  % We also define vector x, due to the space discretization
end

%Boundary Condition
for k = 1:Nt + 1
    u(1,k) = 1.;
    u(Nx + k) = 0.;
    t(k) = (k-1)*Dt; % We also define vector t
end

%Implement of the lax method
for k = 1:Nt
    for i = 2:Nx
        u(i,k+1) = 0.5*(u(i+1,k)+u(i-1,k))+b*(u(i+1,k)-u(i-1,k));
    end
end

plot(x,u(:,1),'-b');                      %time = 1
plot(x,u(:,round(Nt/10)),'--g');          %time = Nt / 10
plot(x,u(:,round(Nt/3)),':b');            %time = Nt / 3
plot(x,u(:,Nt),'-.r');                    %time = Nt 
xlabel('X');
ylabel('Amp(X)');

首先Nt = 300,这样b刚好等于0.5,介于稳定和不稳定之间 

Nt = 400,这样b就小于0.5,可以说是稳定了

Nt = 290,b就大于0.5,不稳定

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值