Please how will I insert this initial data u(x)=1 for -1<x<0 and u(x)=-1/2 for 0<x<=1 in advection equation using backward finite difference
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lmax = -1 t0 1; % Maximum length %Tmax = (4/400); % Maximum time c = 2.0; % Advection velocity % Parameters needed to solve the equation within the Lax method maxt = 40; % Number of time steps dt=(1/400); %dt = Tmax/maxt; n = 200; % Number of space steps nint=40; % The wave-front: intermediate point from which u=0 %(nint<n)!! h = Lmax/n; b = c*dt/(2.*h); % Initial data for i = 1:(n+1) if i < nint u(i,1)=1.; else u(i,1)=-1/2.; end x(i) =(i-1)*h; end
% boundary condition for k=1:maxt+1 u(1,k) = 1.; u(n+1,k) =-1/2.; time(k) = (k-1)*dt; end % Implementation of the Lax friedrich method for k=1:maxt % Time loop for i=2:n % Space loop u(i,k+1) =u(i,k)-b*(u(i,k)-u(i-1,k)); end end
% Graphical representations of the evolution of the eqaution figure(1) mesh(x,time,u') title('Square-wave test within the BDF Method') xlabel('X') ylabel('T') figure(2) plot(x,u(:,10),'-',x,u(:,20),'-',x,u(:,30),'-',x,u(:,40),'-') title('Square-wave test within the BDF Method') xlabel('X') ylabel('Amplitude(X)')
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Behavior and Psychophysics en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!