import theano
import theano.tensor as T
import matplotlib.pyplot as plt
%matplotlib inline
x = T.dscalar('x')
y = T.sin(x)
a = T.dscalar('a')
c0 = y
c1 = T.grad(cost=y, wrt=x)
c2 = T.grad(cost=c1, wrt=x)/2
#c2 = -T.sin(x)/2
taylor = c0 + c1*(x-a) + c2*((x-a)**2)
f = theano.function(inputs=[x, a], outputs=taylor)
f_orig = theano.function(inputs=[x], outputs=y)
import numpy as np
input = np.linspace(-5, 5, 1000)
a = 2
output = [f(input[i], a) for i in range(len(input))]
plt.plot(input, output)
output_orig = [f_orig(input[i]) for i in range(len(input))]
plt.plot(input, output_orig)
print("f(a):{}, orig(a):{}".format(f(a, a), f_orig(a)))
plt.show()
x=aのあたりだとうまく近似できてそう。 これがテイラー展開