using roots with vectorization of a polynomial vs. the function it’s self

x=-100:100
y=5*x.^5+4*x.^4+3*x.^3+2*x.^2+x
r = roots(y)
y1 = [5 4 3 2 1]
r1 = roots(y1)
why do you recieve more roots in the output when you run the roots with a function versus running it with a vectorized version of the coefficients of the function?

 采纳的回答

Look at what the roots function is documented to do.
r = roots(p) returns the roots of the polynomial represented by p as a column vector. Input p is a vector containing n+1 polynomial coefficients, starting with the coefficient of xn.
It does not accept a vector of values of your function and find the zeros of the function that takes those values. In other words, since x has 201 elements so does y and so r is the roots of a 200th degree polynomial not the 5th degree polynomial you evaluated to compute y. Zero crossings in a vector is better done by comparing the sign of the elements in that vector, or perhaps interpolation and fzero.
On the other hand, y1 does not represent the polynomial you evaluated to compute y. You're missing the constant term, which has to be present in the coefficient vector even if it's 0. But it's closer.

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Polynomials 的更多信息

产品

版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by