In sage it is fairly easy to do a Taylor expansion of an unknown function f(x),
x = var(\'x\')
h = var(\'h\')
f = function(\'f\',x)
g1 = taylor(f,x,h,2)
There is no function for this in sympy, but it's rather easy to do it "by hand":
In [3]: from sympy import *
x, h = symbols('x, h')
f = Function('f')
sum(h**i/factorial(i) * f(x).diff(x, i) for i in range(4))
Out[3]: h**3*Derivative(f(x), x, x, x)/6 + h**2*Derivative(f(x), x, x)/2 + h*Derivative(f(x), x) + f(x)
Note that sympy typically works with expressions (like f(x)
) and not with bare functions (like f
).