File: laxexplicit.m Line: 41 Column: 31 Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
2 ビュー (過去 30 日間)
古いコメントを表示
% Chlorine Decay Flow for the Lax method to solve the advection equation
clear;
% Parameters to definr the advection equation and the range in space and time
D = 1*10^-4; % Heat Conductivity parameter in m2/s
K = 1*10^-4; % Heat Conductivity parameter in s^-1Lmax=100; % Maximum Length in m
Tmax = 43200.; % Maximum time
C = 1.0; % Advection velocity
% Parameters needed to implement the Lax method
Nt = 6; % Number of time steps
Dt = 1; % Time step in seconds
Nx = 51; % Number of space steps
Dx = 0.5; % space step in m
b = -K; % beta parameter in the finite-difference implementation
% Remember that the Lax method is stable for b=< 1/2 but it gets diffused unless abs(b) = 1/2
% Initial condition: the initial value of the u function (amplitude of the wave initially)
Nfront = round(Nx/2); % The wave-front: intermediate point from which u=0
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 space discretization
end
% Boundary conditions: value of the u function at the boundaries at any time
for k=1:Nt+1
u(1,k) =1.;
u(Nx+1,k)= 0.;
t(k) = (k-1)*Dt; % we also define vector t, due to the time discretization
end
% Implementation of the Lax mathod
for k=1:Nt %Time loop
for i =2:Nx % Space loop
u(i,k+1) = 1/2*(u(i+1),k + u(i-1),k) - D*Dt/2*Dx*(u(i+1),k-u(i-1),k);
end
end
% Graphical representations of the evolution of the pipe
plot(x,u(:,1), '-b',x,u(:,round(Nt/10)),'--g',x,u(:,round(Nt/3)),':b',x,u(:,Nt),'-.r')
Title ('Pipe flow test within Lax method')
xlabel('X')
ylabel('Amplitude(X)')
I need to plot my profile C vs x at t =[2,4,6,8,10,12]
I think i messed up the labelling part
0 件のコメント
回答 (1 件)
Voss
2022 年 4 月 6 日
There were some syntax errors in the calculation of u(i,k+1). I made a guess at fixing them. (And another syntax error in "Title" - should be "title".) See if it looks right now:
% Chlorine Decay Flow for the Lax method to solve the advection equation
clear;
% Parameters to definr the advection equation and the range in space and time
D = 1*10^-4; % Heat Conductivity parameter in m2/s
K = 1*10^-4; % Heat Conductivity parameter in s^-1Lmax=100; % Maximum Length in m
Tmax = 43200.; % Maximum time
C = 1.0; % Advection velocity
% Parameters needed to implement the Lax method
Nt = 6; % Number of time steps
Dt = 1; % Time step in seconds
Nx = 51; % Number of space steps
Dx = 0.5; % space step in m
b = -K; % beta parameter in the finite-difference implementation
% Remember that the Lax method is stable for b=< 1/2 but it gets diffused unless abs(b) = 1/2
% Initial condition: the initial value of the u function (amplitude of the wave initially)
Nfront = round(Nx/2); % The wave-front: intermediate point from which u=0
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 space discretization
end
% Boundary conditions: value of the u function at the boundaries at any time
for k=1:Nt+1
u(1,k) =1.;
u(Nx+1,k)= 0.;
t(k) = (k-1)*Dt; % we also define vector t, due to the time discretization
end
% Implementation of the Lax mathod
for k=1:Nt %Time loop
for i =2:Nx % Space loop
% u(i,k+1) = 1/2*(u(i+1),k + u(i-1),k) - D*Dt/2*Dx*(u(i+1),k-u(i-1),k);
u(i,k+1) = 1/2*(u(i+1,k) + u(i-1,k)) - D*Dt/2*Dx*(u(i+1,k) - u(i-1,k));
end
end
% Graphical representations of the evolution of the pipe
plot(x,u(:,1), '-b',x,u(:,round(Nt/10)),'--g',x,u(:,round(Nt/3)),':b',x,u(:,Nt),'-.r')
% Title ('Pipe flow test within Lax method')
title('Pipe flow test within Lax method')
xlabel('X')
ylabel('Amplitude(X)')
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Particle & Nuclear Physics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!