我正在寫一個代碼來解決「平流方程」,它表達了給定性質或物理量隨時間變化的方式。爲此我有這樣的表達:https://gyazo.com/f531cb756ffbd3ec28ab85ea1f09b18d 這是我的問題之一,我不知道如何實現它。 這是我的時刻代碼:Matlab 1D Advection
%%Our paramatres
k = 1e-4;
x = [1 2 2.1 13.9 14 28 28.1 39.9 40 59 69 79 150];
y = [3000 3000 3150 3150 3000 3000 3080 3080 3000 3000 3150 3000 3000];
vx = 0.1; % velocity in x m/s
tmax = 250; %time max
xmin = min(x);
xmax = max(x);
axis([0 150 2990 3160])
plot(x,y,'--')
%% discretization of domain
%
dx = 150;
dt = dx/(5*vx); % delta time is equal delta x * vx
n = tmax/dt ;
m = (xmax - xmin)/dx;
x = linspace(xmin,xmax,m+1); % é igual a x = xmin:dx:xmax
%% Stability condition
%
lambda = k * dt/vx^2;
while lambda > 1/2
fprintf ('Satisfied\n\n')
fprintf ('Value of dt is %5.1f and for z is %i \n\n', dt,dx)
dt = input('New value for dt: ')
dx = input ('New value for dx: ')
lambda = k*dt/dx^2;
n = tmax/dt;
m = xmax/dx;
x = linspace(xmin,xmax,m+1);
end
%%Initial conditions and frontier
%
h = zeros(size(x));
h(x>0)=1;
plot(x,h)
xlabel('Distance')
ylabel('Density')
grid on
爲您正在使用的語言添加標記可能很有用。 – beaker
噢謝謝你:) –