Roots command in MATLAB

  • #1

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
 

Answers and Replies

  • #2
1,441
1,301
Follow this code:
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
 

Related Threads on Roots command in MATLAB

  • Last Post
Replies
4
Views
24K
Replies
4
Views
13K
  • Last Post
Replies
1
Views
2K
Replies
1
Views
495
  • Last Post
Replies
11
Views
1K
  • Last Post
Replies
1
Views
585
Replies
1
Views
16K
Replies
1
Views
609
Replies
4
Views
787
Replies
2
Views
5K
Top