clc
clear
t = 0:0.01:10;
xA = 0.6 .* t;
xB = 0.05 .* t.^2 + 0.1 .* t + 0.5;
plot(t, xA, 'b-', 'LineWidth', 2);
plot(t, xB, 'r-', 'LineWidth', 2);
meetingTimes = sort(roots([0.05, -0.5, 0.5]));
meetingPositions = 0.6 .* meetingTimes;
plot(meetingTimes, meetingPositions, 'ko', 'MarkerFaceColor', 'k');
xlabel('Time (s)');
ylabel('Position');
title('Position of carts A and B versus time');
legend('Cart A', 'Cart B', 'Where carts pass', 'Location', 'best');
grid on;
fprintf('First meeting: t = %.2f s, x = %.2f\n', meetingTimes(1), meetingPositions(1));
fprintf('Second meeting: t = %.2f s, x = %.2f\n', meetingTimes(2), meetingPositions(2));
To embed this project on your website, copy the following code and paste it into your website's HTML: