0

在此处输入图像描述

我得到了这样一个 Ryacas 表达式,我想提取 x^4,11 的系数。我应该如何编写代码来获得这个,谢谢。

4

1 回答 1

0

希望这可以帮助:

x <- Sym("x")
P <- (x+1)*(x+2)*(x+3)
Expand(P)
# expression(x^3 + 6 * x^2 + 11 * x + 6)
# coefficient of x^2:
yacas("Coef((x+1)*(x+2)*(x+3), x, 2)")
# expression(6)
# or:
yacas(paste0("Coef(", P, ",x , 2)"))
# expression(6)

编辑 2020-02

更新了新版本Ryacas

library(Ryacas)
x <- ysym("x")
yac_assign((x+1)*(x+2)*(x+3), "P")
### expand the polynomial
yac_str("Expand(P)")
# [1] "x^3+6*x^2+11*x+6"
### extract coefficient of x^2:
yac_str("Coef(P, x, 2)")
# [1] "6"
于 2019-03-19T10:46:41.440 回答