从Ryacas计算表达式中提取x ^ k的系数

时间:2019-03-19 04:22:17

标签: r yacas

enter image description here

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

1 个答案:

答案 0 :(得分: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)