Here's an example that duplicates the issue.
% Gets input from the user.
m2 = [5 6];%input('Enter mass m2 (e.g. 5): ');
m3 = 10;%input('Enter mass m3 (e.g. 10): ');
k = 2000;%input('Enter the spring constant k (e.g. 2000): ');
c = 50;%input('Enter the damping factor c (e.g. 50): ');
V2 = 2;%input('Enter the initial velocity V2 (e.g. 2): ');
% Calculate damping ratio xi, natural frequency omega, and damped frequency omega_d
xi = c / (2 * sqrt(k * (m2 * m3) / (m2 + m3)));
omega = sqrt(k * (m2 + m3) / (m2 * m3) );
omega_d = omega * sqrt(1 - xi^2);
% Set time range
t_vals = linspace(0, 5, 1000);
% y2(t)
y2_vals = V2 * (m2 / (m2 + m3)) * ( (m3 / m2) * (1 / omega_d) ...
* exp(-xi * omega * t_vals) .* sin(omega_d * t_vals) + t_vals );
% y3(t)
y3_vals = V2 * (m2 / (m2 + m3)) * ((-1 / omega_d) ...
* exp(-xi * omega * t_vals) .* sin(omega_d * t_vals) + t_vals );
% Graph settings for animation figure;
h1 = animatedline('Color', 'b', 'LineWidth', 2);
h2 = animatedline('Color', 'r', 'LineWidth', 2);
xlabel('Time (seconds)', 'FontSize', 12);
ylabel('Displacement (meters)', 'FontSize', 12);
title('Animation of mass displacement over time', 'FontSize', 14);
legend('y_2(t)', 'y_3(t)', 'FontSize', 12);
grid on