% Define time intervals and acceleration
T1 = 1.2;
T2 = 2;
T3 = 3.2;
% Define acceleration profile
a = [0 -2.5 -2.5 0];
% Create time vector
t = [0 T1 T2 T3];
% Interpolate the acceleration profile for smoother plot
t_interp = linspace(0, T3, 1000); % More time points for interpolation
a_interp = interp1(t, a, t_interp, 'linear');
% Calculate velocity and position using numerical integration (trapezoidal rule)
v = zeros(size(t_interp));
s = zeros(size(t_interp));
for i = 2:length(t_interp)
v(i) = v(i-1) + a_interp(i)*(t_interp(i)-t_interp(i-1));
s(i) = s(i-1) + v(i-1)*(t_interp(i)-t_interp(i-1)) + 0.5*a_interp(i)*(t_interp(i)-t_interp(i-1))^2;
end
% Plot the results
figure(1);
subplot(3,1,1);
plot(t_interp, a_interp, 'LineWidth', 1.5);
xlabel('Time (s)');
ylabel('Acceleration (m/s^2)');
title('Acceleration');
grid on;
xticks(0:0.5:3); % Set x-axis ticks
xlim([0 3.2]); % Set x-axis limits
ylim([-3 0]); % Set y-axis limits
subplot(3,1,2);
plot(t_interp, v, 'LineWidth', 1.5);
xlabel('Time (s)');
ylabel('Velocity (m/s)');
title('Velocity');
grid on;
xticks(0:0.5:3); % Set x-axis ticks
xlim([0 3.2]); % Set x-axis limits
ylim([0 5]); % Set y-axis limits to ensure velocity starts at 5 and decreases
subplot(3,1,3);
plot(t_interp, s, 'LineWidth', 1.5);
xlabel('Time (s)');
ylabel('Position (m)');
title('Position');
grid on;
xticks(0:0.5:3); % Set x-axis ticks
xlim([0 3.2]); % Set x-axis limits
ylim([0 3]); % Set y-axis limits
Mathbot Says...
I wasn't able to parse your question, but the HE.NET team is hard at work making me smarter.