L = 200;
K = 99;
j = 2;
omega_d = 1;
beta = 1;
delta = 0.05;
h = L / (K + 1);
n = linspace(-L/2, L/2, K+2);
N = length(n);
omegaDScaled = h * omega_d;
deltaScaled = h * delta;
dt = 1;
tmax = 3000;
tspan = 0:dt:tmax;
a_values = [2, 1.95, 1.9, 1.85, 1.82];
function dYdt = odefun(~, Y, N, h, omegaDScaled, deltaScaled, beta)
U = Y(1:N);
Udot = Y(N+1:end);
Uddot = zeros(size(U));
for k = 2:N-1
Uddot(k) = (U(k+1) - 2 * U(k) + U(k-1)) ;
end
dUdt = Udot;
dUdotdt = Uddot - deltaScaled * Udot + omegaDScaled^2 * (U - beta * U.^3);
dYdt = [dUdt; dUdotdt];
end
figure;
a_init = 2;
U0_init = a_init * sin((j * pi * h * n) / L);
U0_init(1) = 0;
U0_init(end) = 0;
subplot(3, 2, 1);
plot(n, U0_init, 'r.-', 'LineWidth', 1.5, 'MarkerSize', 10);
xlabel('$x_n$', 'Interpreter', 'latex');
ylabel('$U_n$', 'Interpreter', 'latex');
title('$t=0$', 'Interpreter', 'latex');
set(gca, 'FontSize', 12, 'FontName', 'Times');
xlim([-L/2 L/2]);
ylim([-3 3]);
grid on;
for i = 1:length(a_values)
a = a_values(i);
U0 = a * sin((j * pi * h * n) / L);
U0(1) = 0;
U0(end) = 0;
Udot0 = zeros(size(U0));
Y0 = [U0, Udot0];
opts = odeset('RelTol', 1e-5, 'AbsTol', 1e-6);
[t, Y] = ode45(@(t, Y) odefun(t, Y, N, h, omegaDScaled, deltaScaled, beta), tspan, Y0, opts);
U = Y(:, 1:N);
Udot = Y(:, N+1:end);
subplot(3, 2, i+1);
plot(n, U(end,:), 'b.-', 'LineWidth', 1.5, 'MarkerSize', 10);
xlabel('$x_n$', 'Interpreter', 'latex');
ylabel('$U_n$', 'Interpreter', 'latex');
title(['$t=3000$, $a=', num2str(a), '$'], 'Interpreter', 'latex');
set(gca, 'FontSize', 12, 'FontName', 'Times');
xlim([-L/2 L/2]);
ylim([-2 2]);
grid on;
end
set(gcf, 'Position', [100, 100, 1200, 900]);