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
endI 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 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 pde MATLAB Answers — New Questions