【发布时间】:2018-11-13 12:04:32
【问题描述】:
但是我不认为我在我的函数中正确输入了多项式本身。 函数代码:
directpoly1 <- function(x, coef, seqcoef = seq(coef) - 1) {
sum(coef*x^seqcoef)
}
directpoly <- function(x, coef) {
seqcoef <- seq(coef) - 1
sapply(x, directpoly1, coef, seqcoef)
}
函数使用代码:
directpoly(x=seq(-10,10, length=5000000), rep(c(2,-1),20))
关于如何正确输入的任何想法?
【问题讨论】:
-
试试
seqcoef = seq_along(coef)。这意味着您需要在向量coef中包含零系数。 -
谢谢!你能看看我是否正确使用了这个函数,所以当用我的函数评估 P(x) 时,P(x) 是否正确输入?
标签: r polynomials