Select one root of an second degree equation

7 vues (au cours des 30 derniers jours)
Pavel
Pavel le 1 Juin 2013
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

Réponse acceptée

Roger Stafford
Roger Stafford le 1 Juin 2013
You could also use the formula for second degree equations. If the equation is:
a*x^2 + b*x + c = 0
then get the positive root, (if there is just one,) with:
r = (-b + sign(a)*sqrt(b^2-4*a*c))/(2*a);
  2 commentaires
Walter Roberson
Walter Roberson le 2 Juin 2013
There could be multiple positive roots; the above would give the greater of the two.
Roger Stafford
Roger Stafford le 2 Juin 2013
That's why I said "if there is just one [positive root]".

Connectez-vous pour commenter.

Plus de réponses (3)

Andrei Bobrov
Andrei Bobrov le 1 Juin 2013
Modifié(e) : Andrei Bobrov le 1 Juin 2013
p = [3 -6 -7];
r = roots(p);
out = r(r>0);
  2 commentaires
Andrei Bobrov
Andrei Bobrov le 1 Juin 2013
about positive root
Walter Roberson
Walter Roberson le 1 Juin 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.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 1 Juin 2013
r = roots(...);
r(1)
Did you care which root it displays?
  1 commentaire
Pavel
Pavel le 1 Juin 2013
i want the positive root

Connectez-vous pour commenter.


Pavel
Pavel le 1 Juin 2013
thanks all for replaing

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by