solving nonlinear wave equation
이전 댓글 표시
I need to solve this PDE below.
This is quite similar to the Burgers' equation. However, I can't understand how to get the exact solution to this equation. Please give an explicit solution to a given initial condition. Any initial condition is fine, just as long as the explicit solution is given. I will use it to check if my FDM code is correct.
In addition, if anyone has the code to solving this equation numerically, please post it here.
Thanks in advance!
below is my code.
for i = 2:(step(1)+1) % t
for j = 2:(step(2)+1) % x
rho(i, j) = rho(i-1, j) - v_max*(1-2*(rho(i-1, j)/rho_max))*(dt/dx)*(rho(i-1, j) - rho(i-1, j-1));
end
end
%----------- set up ---------------
tspan = [0, 3]; % t
xspan = [-10, 10]; % x
step = [1000, 1000]; % step(1) : t, step(2) : x
t_values = linspace(tspan(1), tspan(2), step(1)+1);
x_values = linspace(xspan(1), xspan(2), step(2)+1);
v_max = 5; rho_max = 5; % vmax, rhomax
dt = (tspan(2) - tspan(1)) / step(1);
dx = (xspan(2) - xspan(1)) / step(2);
rho = zeros(step(1)+1, step(2)+1);
rhoo = zeros(step(1)+1, step(2)+1);
for j = 1:(step(1)+1)
rho(1, j) = 1/(1 + exp(j*dt));
end
%------------- (FDM) -------------
for i = 2:(step(1)+1) % t
for j = 2:(step(2)+1) % x
rho(i, j) = rho(i-1, j) - v_max*(1-2*(rho(i-1, j)/rho_max))*(dt/dx)*(rho(i-1, j) - rho(i-1, j-1));
end
end
% for i = 1:(step(1)+1)
% for j = 1:(step(2)+1)
% rhoo(i, j) =
% end
% end
%------------ animation --------------
filename = 'animation.gif';
figure;
for i = 1:(step(1)+1)
plot(x_values, rho(i, :));
xlabel('Position');
ylabel('Density');
title(['Time = ', num2str(t_values(i))]);
drawnow;
frame = getframe(gcf);
img = frame2im(frame);
[imind, cm] = rgb2ind(img, 256);
if i == 1
imwrite(imind, cm, filename, 'gif', 'Loopcount', inf, 'DelayTime', dt);
else
imwrite(imind, cm, filename, 'gif', 'WriteMode', 'append', 'DelayTime', dt);
end
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 PDE Solvers에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

