%calculate the square of distance between A and (0, 0), and between B and %(0, 0). Actually, we only care about the coefficients A = [320^2, -2*320*800, 800^2]; % Location_A = 800 - 320*t B = [160^2, -2*160*410, 410^2]; % Location_B = 410 - 160*t %the square of distance between them D = A + B; x= [0: 0.1: 5]; f = polyval(D, x); %determine when we get the min distance, with precision of 0.1 [a, i] = min(f); %the index is i-1 because we start from time 0 time_to_reach_min_distance = (i-1)*0.1 %sqrt(f) is the real distance %here, we got the bound from time_to_reach_min_distance y = [0: 0.1: time_to_reach_min_distance]; g = polyval(D, y); plot(y, sqrt(g)) E = D - [0, 0, 30^2]; %calculate the roots. While we have two root, we only keep the first one as %stated in the problem roots(E)