Numerical Simulation of a Damped, Driven Nonlinear Wave System with Spatially Extended Initial Conditions
The equation is:
We consider spatially extended initial conditions of the form:
where is the distance of the grid and is the amplitude of the initial condition
We also assume zero initial velocity:
I am trying to create the following plots but as you can see my code doesn;t give these results. Any sugestions?
% Parameters
K = 99;
L = 200;
beta = 1;
delta = 0.05;
omega_d = 1;
h = L / (K + 1);
Omega_d_squared = h^2 * omega_d^2;
hat_delta = h * delta;
% Discrete Laplacian
laplacian = @(U) [U(2) – 2*U(1) + U(1); U(3:end) – 2*U(2:end-1) + U(1:end-2); U(end) – 2*U(end) + U(end-1)];
% Differential Equation
equation = @(t, U_flat) [U_flat(K+1:end); laplacian(U_flat(1:K)) – hat_delta * U_flat(K+1:end) + Omega_d_squared * (U_flat(1:K) – beta * U_flat(1:K).^2)];
% Initial Conditions Function
initial_conditions = @(a) [a * sin(pi * (1:K)’ * h / L); zeros(K, 1)];
% Time Span
t_span = [0 3000];
t_eval = linspace(0, 3000, 600);
% Solver options
options = odeset(‘RelTol’,1e-4, ‘AbsTol’,1e-6);
% Amplitudes to test
amplitudes = [2, 1.95, 1.9, 1.85, 1.82];
% Create Subplots
figure;
for i = 1:length(amplitudes)
a = amplitudes(i);
U0 = initial_conditions(a);
[t, U_flat] = ode15s(@(t, U_flat) equation(t, U_flat), t_eval, U0, options);
U = U_flat(:, 1:K);
subplot(3, 2, i);
plot(t, U(:, round(K/2)), ‘DisplayName’, [‘a=’ num2str(a)]);
title([‘a=’ num2str(a)]);
xlabel(‘t’);
ylabel(‘U_n’);
legend;
% Zoom-in subplot
ax = axes(‘Position’, [.15 + mod(i-1,2)*.45 .65 – floor((i-1)/2)*.35 .2 .2]);
plot(ax, 1:K, U(end, :), ‘bo-‘);
title(ax, [‘t=’ num2str(t_span(end))]);
xlabel(ax, ‘x_n’);
ylabel(ax, ‘U_n’);
end
% Hide unused subplot
subplot(3, 2, 6); % Placeholder for unused subplot
axis off; % Turn off the axis for the unused subplot
% Adjust layout
sgtitle(‘Dynamics for initial condition and various amplitude values’);
% Hide unused subplot
subplot(3, 2, 6); % Placeholder for unused subplot
axis off; % Turn off the axis for the unused subplot
% Adjust layout
sgtitle(‘Dynamics for initial condition and various amplitude values’);The equation is:
We consider spatially extended initial conditions of the form:
where is the distance of the grid and is the amplitude of the initial condition
We also assume zero initial velocity:
I am trying to create the following plots but as you can see my code doesn;t give these results. Any sugestions?
% Parameters
K = 99;
L = 200;
beta = 1;
delta = 0.05;
omega_d = 1;
h = L / (K + 1);
Omega_d_squared = h^2 * omega_d^2;
hat_delta = h * delta;
% Discrete Laplacian
laplacian = @(U) [U(2) – 2*U(1) + U(1); U(3:end) – 2*U(2:end-1) + U(1:end-2); U(end) – 2*U(end) + U(end-1)];
% Differential Equation
equation = @(t, U_flat) [U_flat(K+1:end); laplacian(U_flat(1:K)) – hat_delta * U_flat(K+1:end) + Omega_d_squared * (U_flat(1:K) – beta * U_flat(1:K).^2)];
% Initial Conditions Function
initial_conditions = @(a) [a * sin(pi * (1:K)’ * h / L); zeros(K, 1)];
% Time Span
t_span = [0 3000];
t_eval = linspace(0, 3000, 600);
% Solver options
options = odeset(‘RelTol’,1e-4, ‘AbsTol’,1e-6);
% Amplitudes to test
amplitudes = [2, 1.95, 1.9, 1.85, 1.82];
% Create Subplots
figure;
for i = 1:length(amplitudes)
a = amplitudes(i);
U0 = initial_conditions(a);
[t, U_flat] = ode15s(@(t, U_flat) equation(t, U_flat), t_eval, U0, options);
U = U_flat(:, 1:K);
subplot(3, 2, i);
plot(t, U(:, round(K/2)), ‘DisplayName’, [‘a=’ num2str(a)]);
title([‘a=’ num2str(a)]);
xlabel(‘t’);
ylabel(‘U_n’);
legend;
% Zoom-in subplot
ax = axes(‘Position’, [.15 + mod(i-1,2)*.45 .65 – floor((i-1)/2)*.35 .2 .2]);
plot(ax, 1:K, U(end, :), ‘bo-‘);
title(ax, [‘t=’ num2str(t_span(end))]);
xlabel(ax, ‘x_n’);
ylabel(ax, ‘U_n’);
end
% Hide unused subplot
subplot(3, 2, 6); % Placeholder for unused subplot
axis off; % Turn off the axis for the unused subplot
% Adjust layout
sgtitle(‘Dynamics for initial condition and various amplitude values’);
% Hide unused subplot
subplot(3, 2, 6); % Placeholder for unused subplot
axis off; % Turn off the axis for the unused subplot
% Adjust layout
sgtitle(‘Dynamics for initial condition and various amplitude values’); The equation is:
We consider spatially extended initial conditions of the form:
where is the distance of the grid and is the amplitude of the initial condition
We also assume zero initial velocity:
I am trying to create the following plots but as you can see my code doesn;t give these results. Any sugestions?
% Parameters
K = 99;
L = 200;
beta = 1;
delta = 0.05;
omega_d = 1;
h = L / (K + 1);
Omega_d_squared = h^2 * omega_d^2;
hat_delta = h * delta;
% Discrete Laplacian
laplacian = @(U) [U(2) – 2*U(1) + U(1); U(3:end) – 2*U(2:end-1) + U(1:end-2); U(end) – 2*U(end) + U(end-1)];
% Differential Equation
equation = @(t, U_flat) [U_flat(K+1:end); laplacian(U_flat(1:K)) – hat_delta * U_flat(K+1:end) + Omega_d_squared * (U_flat(1:K) – beta * U_flat(1:K).^2)];
% Initial Conditions Function
initial_conditions = @(a) [a * sin(pi * (1:K)’ * h / L); zeros(K, 1)];
% Time Span
t_span = [0 3000];
t_eval = linspace(0, 3000, 600);
% Solver options
options = odeset(‘RelTol’,1e-4, ‘AbsTol’,1e-6);
% Amplitudes to test
amplitudes = [2, 1.95, 1.9, 1.85, 1.82];
% Create Subplots
figure;
for i = 1:length(amplitudes)
a = amplitudes(i);
U0 = initial_conditions(a);
[t, U_flat] = ode15s(@(t, U_flat) equation(t, U_flat), t_eval, U0, options);
U = U_flat(:, 1:K);
subplot(3, 2, i);
plot(t, U(:, round(K/2)), ‘DisplayName’, [‘a=’ num2str(a)]);
title([‘a=’ num2str(a)]);
xlabel(‘t’);
ylabel(‘U_n’);
legend;
% Zoom-in subplot
ax = axes(‘Position’, [.15 + mod(i-1,2)*.45 .65 – floor((i-1)/2)*.35 .2 .2]);
plot(ax, 1:K, U(end, :), ‘bo-‘);
title(ax, [‘t=’ num2str(t_span(end))]);
xlabel(ax, ‘x_n’);
ylabel(ax, ‘U_n’);
end
% Hide unused subplot
subplot(3, 2, 6); % Placeholder for unused subplot
axis off; % Turn off the axis for the unused subplot
% Adjust layout
sgtitle(‘Dynamics for initial condition and various amplitude values’);
% Hide unused subplot
subplot(3, 2, 6); % Placeholder for unused subplot
axis off; % Turn off the axis for the unused subplot
% Adjust layout
sgtitle(‘Dynamics for initial condition and various amplitude values’); plot, plotting, differential equations, subplot, equation MATLAB Answers — New Questions