泰勒公式学过微积分都应该知道,可以翻wiki复习一下,https://zh.wikipedia.org/wiki/泰勒公式.

用R简单实现一下:

 efv <- function(f, value, variable="x", a=0, eps=0.001) {
     #estimate function value using Taylor theorem
     assign(eval(variable), a)
     fv.old <- eval(f)
     k <- 1     
     repeat {
         df <- D(f, variable)
         if (df == 0)
             break
         fv.new <- fv.old + eval(df)*(value-a)^k/factorial(k)
         if (fv.new - fv.old < eps)
             break
         fv.old <- fv.new
         f <- df
         k <- k+1
     }
     return (fv.new)
 }

Continue reading

Author's picture

Guangchuang Yu

a senior-in-age-but-not-senior-in-knowledge bioinformatician

Postdoc researcher

Hong Kong