python - Taylor Expansion for given dataset without functional form -


i have (x,y) dataset continuous , differentiable. exact functional form not known. want taylor expand graph @ point. have tried using algopy/adipy. problem demand functional form.

i attaching sample code of algopy.

 import numpy; numpy import sin,cos  algopy import utpm   def f(x):      return sin(cos(x) + sin(x))  d = 100; p = 1 x = utpm(numpy.zeros((d,p))) x.data[0,0] = 0.3 x.data[1,0] = 1 y = f(x) print('coefficients of y =', y.data[:,0]) 

where d order of polynomial.

i tried using following (x1 , y1 1d arrays):

from scipy.interpolate import interp1d f1 = interp1d(x1, y1, kind='cubic') def f(x):     temp1=f1(x)     return np.float64(temp1) 

however, interpolation not seem take in data type of x returned utpm.

error message:

traceback (most recent call last):       file "tay.py", line 26, in <module>         y = f(x)       file "tay.py", line 15, in f         temp1=f1(x)       file "/usr/lib/python2.7/dist-packages/scipy/interpolate/polyint.py", line 54, in __call__         y = self._evaluate(x)       file "/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py", line 449, in _evaluate         y_new = self._call(self, x_new)       file "/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py", line 441, in _call_spline         return spleval(self._spline, x_new)       file "/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py", line 919, in spleval         res[sl] = _fitpack._bspleval(xx,xj,cvals[sl],k,deriv)     typeerror: cannot cast array data dtype('o') dtype('float64') according rule 'safe' 

doing taylor expansion of dataset defined @ discrete points not makes sense. in particular, following preposition wrong,

i have (x,y) dataset continuous , differentiable. exact functional form not known.

you can have continuous function, if associate interpolation procedure dataset, fix general functional form.

for instance, use piecewise cubic interpolations, in question. means taylor expansion, constrained coefficients of cubic polynomial used interpolation (and can @ of order 3). in addition, interpolation routine produce different taylor expansion.

in general, results depend on interpolation routine instead of on data. because taylor expansion relies on local behaviour of function, not contained in (x,y) dataset.

instead, locally fit data polynomial of order, yield equivalent of taylor expansion sampled data.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -