clc
clear
disp "Taylor Waller"
t=linspace(0,10,500);
X_A=0.6 * t;
X_B=0.5 * t.^2 + 0.1 * t + 0.5;
figure;
plot(t, X_A, 'b-', 'Linewidth',2); hold on;
plot(t,X_B, 'r--', 'Linewidth', 2);
xlabel('Time (t) [s]');
ylabel('Position (X) [m]');
title('Position vs Time for Carts A and B');
legend('Cart A','Cart B');
grid on;
[min_diff, idx]= min(abs(X_A - X_B));
t_pass=t(idx);
x_pass=X_A(idx);
plot(t_pass, x_pass, 'go', 'MarkerSize', 8, 'MarkerFaceColor','g');
text(t_pass + 0.3, x_pass, sprintf('Intersection:t=%.2fs, X=%.2fm',t_pass, x_pass));
fprintf('The two carts pass each other roughly at t=%.2f seconds at position X=%.2f meters.\n',t_pass, x_pass);
To embed this project on your website, copy the following code and paste it into your website's HTML: