简体   繁体   English

给定包含R根的向量,如何计算多项式的系数

[英]How to compute the coefficients of a polynomial given a vector containing the roots in R

I want to compute the coefficients of a polynomial based on a vector containing the roots. 我想基于包含根的向量来计算多项式的系数。 I first defined a vector of coefficients: 我首先定义了一个系数向量:

pol <- c(0,1,2,3,4) 

and computed the roots 并计算了根

roots <- polyroot(pol)

to have a test result. 获得测试结果。 Then i tried the following: 然后我尝试了以下方法:

result <- 1
for (n in 1:(length(roots))){
result <- c(result, 0) + c(0,-roots[n]*result)
}

But the my result is the following: 但是我的结果如下:

result 
[1] 1.00+0i 0.75+0i 0.50+0i 0.25+0i 0.00+0i

What am I missing here? 我在这里想念什么?

Notice that 注意

identical(polyroot(pol), polyroot(pol / 4))
# [1] TRUE

That is, by going from a polynomial to its roots you lose information about the coefficient of the highest degree term (in this case, 4). 也就是说,通过从多项式到其根,您将丢失有关最高次数项的系数的信息(在这种情况下为4)。 For instance, 2x^2-x=2x(x-1/2), but also x^2-x/2=x(x-1/2), so that the roots are the same and we only normalized the first polynomial with respect to the quadratic term. 例如,2x ^ 2-x = 2x(x-1 / 2),但是x ^ 2-x / 2 = x(x-1 / 2),因此根相同,我们只对第一个进行归一化关于二次项的多项式。 So, 所以,

Re(result) * 4
# [1] 4 3 2 1 0

gives the result but also requires the knowledge of tail(pol, 1) . 给出结果,但还需要知道tail(pol, 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM