"roots" function not working

5 ビュー (過去 30 日間)
Kyle
Kyle 2011 年 3 月 1 日
コメント済み: Anowarul Azim Evan 2021 年 3 月 18 日
Hi,
I need to use the roots function to find the roots of a polynomial. I copied the text from the example @ the MathWorks.com entry for this function:
p = [1 -6 -72 -27];
r = roots(p);
However, r does not return, and the following error appears:
??? Subscript indices must either be real positive integers or logicals.
I cannot believe that Matlab cannot execute this simple code that is an official example. Does someone have any insight as to what the problem may be?

採用された回答

Matt Fig
Matt Fig 2011 年 3 月 1 日
You have a variable named roots. Do this :
clear roots
p = [1 -6 -72 -27];
r = roots(p);
Don't name variables after built-in MATLAB functions. (And especially don't blame MATLAB for your silly mistakes ;-))
  3 件のコメント
Kyle
Kyle 2011 年 3 月 2 日
This was my problem. Oops. Thank you very much.
Anowarul Azim Evan
Anowarul Azim Evan 2021 年 3 月 18 日
rt=[1 1 1 1 1]; % all roots are 1 like (x-1)*(x-1)*(x-1)*(x-1)*(x-1)
p=poly(rt) % right-most is the constant value then x coefficient, then x^2 and so on...
roots(p)
%% roots
1.0008 + 0.0006i
1.0008 - 0.0006i
0.9997 + 0.0009i
0.9997 - 0.0009i
0.9990 + 0.0000i
%% Is it any bug? I was supposed to get 5 ones as roots.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by