Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The (x, y) coordinates of a certain object as a function of time t are given by

ID: 1854447 • Letter: T

Question


The (x, y) coordinates of a certain object as a function of time t are given by x(t) = 5t - 10 y(t) = 25t2 - 120t + 144 for 0 t 4. Write a program to determine the time at which the object is the closest to the origin at (0, 0). Determine also the minimum distance. Do this in two ways: By using a for loop. By not using a for loop.

Explanation / Answer

CODE USING FOR LOOP % Initialize the minimum distance to the distance at t=0 min_d = (-10)^2 + 144^2; min_t = 0; for t = 0:4 x = 5*t - 10; y = 25*t*t - 120*t + 144; d = x^2 + y^2; if min_d > d min_d = d; min_t = t; end end fprintf('Time for minimum distance = %d ', min_t); fprintf('Minimum Distance = %d ', min_d); CODE WITHOUT USING FOR LOOP d = []; d(1) = (-10)^2 + 144^2; d(2) = (5*1-10)^2 + (25*1*1 - 120*1 + 144)^2; d(3) = (5*2-10)^2 + (25*2*2 - 120*2 + 144)^2; d(4) = (5*3-10)^2 + (25*3*3 - 120*3 + 144)^2; d(5) = (5*4-10)^2 + (25*4*4 - 120*4 + 144)^2; min_d = min(d); min_t = find(d==min_d) - 1; fprintf('Time for minimum distance = %d ', min_t); fprintf('Minimum Distance = %d ', min_d);