give me invalid use of operator at U, why?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nx = 50;
x = linspace(0,1,Nx+1);
dx = 1/Nx;
xmid = 0.5*(x(1:Nx) + x(2:Nx+1));
u = 1;
tfinal = 1;
CFL = 0.5;
dt = CFL*dx/abs(u);
U = 0.75*exp(-((xmid-0.5)/0.1). 2)';
t = 0;
% Loop until t > tfinal
while (t < tfinal),
Ubc = [U(Nx); U; U(1)]; % This enforces the periodic bc
% Calculate the flux at each interface
F = 0.5* u *( Ubc(2:Nx+2) + Ubc(1:Nx+1)) ...
- 0.5*abs(u)*( Ubc(2:Nx+2) - Ubc(1:Nx+1));
% Calculate residual in each cell
R = F(2:Nx+1) - F(1:Nx);
% Forward Euler step
U = U - (dt/dx)*R;
% Increment time
50 t = t + dt;
% Plot current solution
stairs(x,[U; U(Nx)]);
axis([0, 1, -0.5, 1.5]);
grid on;
drawnow;
end
% overlay exact solution
U = 0.75*exp(-((xmid-0.5)/0.1).ˆ2)';
hold on;
stairs(x,[U; U(Nx)], 'r-');
0 commentaires
Réponses (1)
Walter Roberson
le 13 Oct 2021
U = 0.75*exp(-((xmid-0.5)/0.1). 2)';
my guess is that you wanted
U = 0.75*exp(-((xmid-0.5)/0.1).^2)';
0 commentaires
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!