简体   繁体   English

在R中找到多项式的最大根

[英]Finding the largest roots of a polynomial in R

Is there a way to avoid the complex numbers in 有没有办法避免复数

polyroot {base} ? polyroot {base}?

The help file says: "…polyroot returns the n-1 complex zeros", but I simply need the largest root of a quadratic equation and the complex numbers are too much of a good thing here. 帮助文件说:“…polyroot返回n-1个复数零”,但是我只需要一个二次方程式的最大根,而复数在这里就太好了。 Help is much appreciated! 非常感谢帮助!

When you use this you set the return against an object, say 使用此功能时,您可以针对对象设置收益,例如

roots=polyroot(coefs)

and you can then return the real ones by excluding the imaginary ones via complex::Im() 然后可以通过complex::Im()排除虚数,从而返回实数

which(Im(roots)==0)

If you get complex solutions for a quadratic equation, then there are no real roots. 如果您得到二次方程的复杂解,那么就没有真正的根。

The largest root of the equation x²+px+q is 方程x²+px+q的最大根是

(-p+sqrt(p*p-4*q))/2

if the term inside the square root is non-negative. 如果平方根内的项是非负数。

Or did you mean a root of largest magnitude? 还是你说的是最大的根?

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

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