Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个方程,我想求解m
m
m^2+x*m+1=0
我知道我可以使用polyroot(c(1,x,1)).
polyroot(c(1,x,1))
我想在 R 中绘制这些根以进行变化x,以便为 的每个值绘制多项式的所有实根x。
x
请注意,多项式可能会变得比这更复杂,从而排除了二次或三次公式的应用。
关于我如何做到这一点的任何想法?
谢谢!
I think this will do the trick. Just set X to whatever values you want to evaluate.
X
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)