"roots" function not working
30 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Matt Fig
on 1 Mar 2011
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 Comments
Anowarul Azim Evan
on 18 Mar 2021
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.
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!