2

我有一个方程,我想求解m

m^2+x*m+1=0

我知道我可以使用polyroot(c(1,x,1)).

我想在 R 中绘制这些根以进行变化x,以便为 的每个值绘制多项式的所有实根x

请注意,多项式可能会变得比这更复杂,从而排除了二次或三次公式的应用。

关于我如何做到这一点的任何想法?

谢谢!

4

1 回答 1

8

I think this will do the trick. Just set X to whatever values you want to evaluate.

X <- seq(0, 10, length=21)
roots <- sapply(X, function(x) polyroot(c(1,x,1))) 
roots[abs(Im(roots)) > 1e-10] <- NA
matplot(X, t(roots), pch=1)

enter image description here

于 2012-08-07T16:03:09.210 回答