是否有可能在R中求解代数方程?

M. *_*eil 3 r algebra equation-solving

我想找到以下解决方案:

-x^3+6*x^2+51*x+44=0
Run Code Online (Sandbox Code Playgroud)

但是有了R.有可能吗?

我找到了Ryacas包,但似乎没有人能够使它工作.

可能听起来微不足道,但我无法找到一个简单的方法来做到这一点......

你有其他选择吗?

多谢你们!

小智 8

你可以使用polynom包:

library(polynom)
p <- polynomial(c(44,51,6,-1))
# 44 + 51*x + 6*x^2 - x^3 
solve(p)
# [1] -4 -1 11
Run Code Online (Sandbox Code Playgroud)

但是,你根本可以使用函数polyrootbase包:

polyroot(c(44,51,6,-1))
# [1] -1+0i -4+0i 11+0i
Run Code Online (Sandbox Code Playgroud)

如果你保持真实的部分Re:

Re(polyroot(c(44,51,6,-1)))
# [1] -1 -4 11
Run Code Online (Sandbox Code Playgroud)


Mat*_*erg 6

在这里,我们使用矩阵与其特征多项式之间的关系来求解根.

给定多项式a0 + a1*x^1 + a2*x^2 + x^3,定义矩阵:

0   0  -a0
1   0  -a1
0   1  -a2
Run Code Online (Sandbox Code Playgroud)

该矩阵的特征值是多项式的根.

y = -x用你的多项式方程代替就可以了

y^3 + 6*y^2 - 51*y + 44=0
Run Code Online (Sandbox Code Playgroud)

并给出了这个例子

> z <- matrix(c(0,1,0,0,0,1,-44,51,-6),3,3)
> z
     [,1] [,2] [,3]
[1,]    0    0  -44
[2,]    1    0   51
[3,]    0    1   -6
> eigen(z)
$values
[1] -11   4   1

$vectors
           [,1]        [,2]        [,3]
[1,]  0.6172134  0.73827166  0.98733164
[2,] -0.7715167 -0.67115606 -0.15707549
[3,]  0.1543033 -0.06711561 -0.02243936
Run Code Online (Sandbox Code Playgroud)

或者,因为我们已经取代-yx:

> eigen(-z)$values
[1] 11 -4 -1
Run Code Online (Sandbox Code Playgroud)

见:http://www-math.mit.edu/~edelman/publications/polynomial_roots.pdf