anyone have a clue why roots([1,6,9]) outputs complex numbers?

2 ビュー (過去 30 日間)
Jeremy Cheung
Jeremy Cheung 2019 年 10 月 28 日
回答済み: Walter Roberson 2019 年 10 月 28 日
a = roots([1,6,9])
I was using roots to output the roots of the equation x^2+6x+9=0
this gives:
a =
-3.0000 + 0.0000i
-3.0000 - 0.0000i
when I use other values that create a quadratic equation with equal roots it seems to work fine, can someone explain to me why this is the case?

採用された回答

Walter Roberson
Walter Roberson 2019 年 10 月 28 日
If you switch to format long you will see non zero imaginary parts. Those are caused by roundoff problems with solving the Vandermode system to get the roots.

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2019 年 10 月 28 日
a is correct. use real(a) to get what you want.
  1 件のコメント
Fangjun Jiang
Fangjun Jiang 2019 年 10 月 28 日
Okay, I get it. Good question!
>> a=roots([1 4 4])
a =
-2
-2

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by