Select one root of an second degree equation

조회 수: 16 (최근 30일)
Pavel
Pavel 2013년 6월 1일
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

채택된 답변

Roger Stafford
Roger Stafford 2013년 6월 1일
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
Walter Roberson
Walter Roberson 2013년 6월 2일
There could be multiple positive roots; the above would give the greater of the two.
Roger Stafford
Roger Stafford 2013년 6월 2일
That's why I said "if there is just one [positive root]".

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Andrei Bobrov
Andrei Bobrov 2013년 6월 1일
편집: Andrei Bobrov 2013년 6월 1일
p = [3 -6 -7];
r = roots(p);
out = r(r>0);
  댓글 수: 2
Andrei Bobrov
Andrei Bobrov 2013년 6월 1일
about positive root
Walter Roberson
Walter Roberson 2013년 6월 1일
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.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2013년 6월 1일
r = roots(...);
r(1)
Did you care which root it displays?

Pavel
Pavel 2013년 6월 1일
thanks all for replaing

카테고리

Help CenterFile Exchange에서 Octave에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by