Calculating Taylor Series Expansion of measured data

54 views (last 30 days)
Hey, I have measured data from which I want to approximate the underlying function that generated this data with rational approximation. For this I need to calculate the taylor series expansion of the function. The problem I have now, is that I don't know the function itself (which is what I want to find out). So I tried to generate an anonymous function from the interpolation of my measured data points and wanted to pass this function to the matlab 'taylor()'-function. Since that function only takes a symbolic expression as argument, I tried to use 'sym()' to convert my anonymous function to a symbolic expression, which doesn't work. I am not really experienced with the symbolic concepts of matlab, so this whole idea might sound stupid. I created a short example to show what I did so far:
x = 0:pi/4:2*pi;
y = sin(x); %just as an example, on my real data I do not know which function produced the data
xq = 0:pi/16:2*pi;
f = @(x)(interp1(x,y,xq,'linear'))
g = sym(f);
t = taylor(g);
The errors matlab gives me don't really help me, it's something like "Error in MuPad command: Invalid input. 'expression' expected."
Can anyone tell me what exactly I'm doing wrong here? Or how else I could calculate the taylor series expansion from measured data? Thx in advance. /Daniel

Accepted Answer

John D'Errico
John D'Errico on 2 Jan 2015
Edited: John D'Errico on 3 Jan 2015
Um, how do I say this? It may have seemed to be a good idea to you, but it is arguably a really bad idea, in terms of numerical analysis. Why?
First of all, using interp1 here uses a piecewise linear approximation to your function. You did specify 'linear' interpolation after all. Seriously, how do you expect that to yield estimates of the higher order derivatives? Even a spline interpolant would only yield a minor improvement in this respect. And remember that a spline is a piecewise function. So no matter what, trying to form a Taylor series approximation to a spline is a bad idea, in spades.
As importantly, estimating the derivative of a function from data is an ill-posed problem. You can view it as an attempt to solve an integral equation of the first kind, something that is known to be ill-posed. Ill-posed here indicates that it is an operation that will take any noise in your data, and amplify the errors. And higher order derivatives are more sensitive to this amplification of noise than are lower ones. Ill-posed problems amplify that noise by a massive amount.
The classic way to fit a rational polynomial approximation to data is a simple one. Assume that
y = P(x)/Q(x)
where P and Q are polynomials, and Q has a unit constant term. The unit constant term in Q is important, since at least one coefficient of the ratio MUST be fixed, rather than unknown. Otherwise the ratio would have non-unique coefficients. Then we can write
y*Q(x) - P(x) = 0
or...
y = p0 + p1*x + p2*x^2 + ... pn*x^n - q1*y*x - q2*y*x^2 - ... - qm*y*x^m
We can now expand this to yield a set of coefficients that are linearly estimable using LINEAR least squares, i.e., the backslash operator will now suffice, or use lscov, or pinv. Or use regress if you have the stats toolbox, etc.
There are issues with this linear regression fit of course. The noise in y becomes a problem now, sort of an errors in variables problem. So it would probably be better in theory to use a nonlinear estimation scheme, but the approach I showed is a very common one.
  2 Comments
Daniel
Daniel on 3 Jan 2015
Hey, thankyou for the thorough answer. I read a lecture note about rational approximation. There it was shown how to do a rational approximation given you know the taylor series coefficients and so I thought this was the only way to do it. With some snippets from the web I think I figured it out your way. Thx a lot.
John D'Errico
John D'Errico on 3 Jan 2015
The issue is if you already know all of the derivatives, OR can compute then quite accurately, then you can use the one method. But it is generally a bad idea if all you have is data, especially if there is any noise in that data. Then you need to use a scheme that is more robust to the presence of noise.
And, when I say noise, it can be really tiny noise. An ill-posed problem can amplify even noise in the least significant bits of a double precision number, until that noise dominates the result.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!