"roots" function not working
조회 수: 5 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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
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 Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!