f <- function(x) x^2+x^3+sin(2*x)
g <- function(x) eval(D(body(f),"x"))
h <- function(x) eval(D(D(body(f),"x"),"x"))
k <- function(x) eval(D(D(D(body(f),"x"),"x"),"x"))
D(body(f),"x"); D(D(body(f),"x"),"x"); D(D(D(body(f),"x"),"x"),"x")
2 * x + 3 * x^2 + cos(2 * x) * 2
2 + 3 * (2 * x) - sin(2 * x) * 2 * 2
3 * 2 - cos(2 * x) * 2 * 2 * 2
# pol. di Taylor di grado 3 e punto inziale 0:
# f(0)+g(0)*x+h(0)*x^2/factorial(2)+k(0)*x^3/factorial(3)
library(MASS)
fractions(c(f(0),g(0),h(0)/factorial(2),k(0)/factorial(3)))
[1]    0    2    1 -1/3
polTay <- function(x) 2*x+x^2-1/3*x^3
# ovvero: f(0)+g(0)*x+h(0)/factorial(2)*x^2+k(0)/factorial(3)*x^3
par( mai = c(0.5,0.5,0.1,0.1) )
plot(f,-2,2,col="blue"); abline(h=0,v=0)
plot(polTay,-2,2,add=TRUE,col="red")