# Roots command in MATLAB

## Main Question or Discussion Point

"roots" command in MATLAB

Hey everyone. I'm a new user to Matlab. I must say, it's an awesome program, but not user-friendly at all. I'm having trouble trying to use the "roots" functon. Here's what part b of my problem states:

"Use the roots function to compute the time when the aircraft are first within 30 miles of each other."

The first part of the problem asks me to obtain an expression for the distance "D" between two aircraft as a function of time, for which I have: D=sqrt((800-320*t)^2+(410-160*t)^2) a.k.a. the distance formula.

Since they are asking for the time when they are first within 30 mi of each other, I have set D=30. This gives me: 30=sqrt((800-320*t)^2+(410-160*t)^2). I then used Wolfram Alpha and came up with 2 values for t: 2.43246 and 2.59254. I'm guessing the latter number would be correct, because the problem is set up like a giant triangle, D being the hypotenuse, which decreases as the planes fly closer together.

Can anyone help me set this up using the "roots" equation? I can clarify more if needed. Thanks in advance,
Josh

Related MATLAB, Maple, Mathematica, LaTeX News on Phys.org
Wrichik Basu
Gold Member
Code:
syms t
eqn = 30==sqrt((800-320*t)^2+(410-160*t)^2);
s = simplify(eqn) %simplifies the equation
p = [160 -804 1009]; %the coefficients in decreasing power of t
r = roots(p)
The simplified equation is 160*t^2 - 804*t + 1009 = 0.

The roots come out to be exactly what you've found using Wolfram Alpha.

Here is the documentation for the roots function:
https://in.mathworks.com/help/matlab/ref/roots.html