Select one root of an second degree equation
Show older comments
i have solved a second degree equation in matlab using the roots() command and i want only one root to be displayed. How do i do this in MATLAB? Thank you very much
Accepted Answer
More Answers (3)
Andrei Bobrov
on 1 Jun 2013
Edited: Andrei Bobrov
on 1 Jun 2013
p = [3 -6 -7];
r = roots(p);
out = r(r>0);
2 Comments
Andrei Bobrov
on 1 Jun 2013
about positive root
Walter Roberson
on 1 Jun 2013
Caution: if there are imaginary roots, then only real() of the roots will be considered by the ">" operator. You might want to use
out = r(imag(r) == 0 & r > 0)
to select only positive real roots. If none exist then "out" will be empty.
Pavel
on 1 Jun 2013
0 votes
Categories
Find more on Octave in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!