Obtaining Taylor series coefficients in numerically stable way?

378 Views Asked by At

From a circuit simulator, I get a nonlinear $y=f(x)$ relationship as data points. The relationship looks linear at the first glance but it is a circuit that is considered very nonlinear.

My goal is to model this relationship with a Taylor series expansion $\hat{y} = c_1 x + c_2 x^2 + c_3 x^3$

I obtain the coefficients with numerical differentiation (e.g. diff in MATLAB) from the datapoints. These are the plots of the derivative for a stepsize of $10\mu V$ (not something extraordinarily small) resulting in 20001 datapoints:

enter image description here

Note that the third derivative is very noise and nearly useless.

Now if change the stepsize to 10mV (only 201 datapoints) I get:

enter image description here

This is much less noisy and makes more sense.

However, I want to get the highest accuracy so I would assume the smaller my stepsize the better the results. The opposite is counter intuitive to me. How would I even select the step size?

Is this nonlinear modeling with Taylor series known to be so impractical? (as said, this is not considered a highly linear circuit!)

If not, is there a better way to obtain the derivatives?

1

There are 1 best solutions below

3
On BEST ANSWER

The source of your noise comes from your circuit solver. Circuit solvers typically solve the equations down to some precision , typically $10^{-6}$ relative (only linear systems have exact values down to floating point precision).

If your stepsize is very small, $f(x+\varepsilon) - f(x)$ is also small (on the order of $\varepsilon f'(x)$). Every time you call the diff function, you perform a substraction of two data points. Assuming an absolute uncertainty of $\delta$, after N calls to diff, your absolute uncertainty is of $N^2 \delta$. To get derivatives, you need to divide by $\varepsilon$, which raises the absolute uncertainty to $N^2 \delta \varepsilon^{-N}$ while the numerical scheme error is on the order of $O(\varepsilon)$. This error can become much larger than the numerical scheme error so raising the stepsize $\varepsilon$ will reduce the overall error.

Raising the circuit solver tolerance could alleviate the issue. Otherwise, I would suggest fitting your data to your proposed equation.