Numerical differentiation using 9 data points

I have problems when I try to do numerical differentiation in Matlab. But my question can help me more about numerical analysis than about Matlab.

I have an array with 9 data points that represents f (x) for 9 different x. I need to find f '' (x) numerically. The values ​​of i for x and f (x) are equal

x = [2271.38, 2555.30, 2697.26, 2768.24, 2839.22, 2910.20, 2981.18, 3123.14, 3407.06]

f (x) = [577.4063, 311.3341, 193.0833, 141.3048, 95.1501, 58.8130, 32.4931, 6.99511, 0.1481]

and I can interpolate to get a smooth curve. I use spline interpolation, but is any other interpolation preferable when you are going to differentiate?

I tried different methods:

Simple forward, inverse and central difference coefficients

Wavelet Method: http://www.mathworks.com/matlabcentral/fileexchange/13948-numerical-differentiation-based-on-wavelet-transforms

and derived set: http://www.mathworks.com/matlabcentral/fileexchange/13490-adaptive-robust-numerical-differentiation

Without this, they worked satisfactorily. The second derivative is very unstable with respect to the step length, and the adaptive method in the derived set works terribly poorly. Maybe I'm just using it the wrong way!

Any help is appreciated!

Thanks in advance

+4
source share
2 answers

I suppose you asked a similar question at MATLAB Central the other day. You did not post your data there, so I could not give a good answer.

Estimating a second derivative is a difficult task. This is not a valid issue. Differentiation itself is a noise amplifier, so evaluating the second derivative β€œtwice” as bad. This is simply not an easy task, of course, not very good.

Using this set of points, I decided to evaluate the spline model with

A simple plot tells me, along with your comments, that I expect this function to be a monotonous decreasing function. Apparently, it is asymptotically linear at each end, like a hyperbolic segment, with positive curvature throughout the region.

So now I will use this information to create a model for your data using my SLM toolbar.

slm = slmengine(x,f,'plot','on','decreasing','on','knots',20, ... 'concaveup','on','endconditions','natural'); 

slmengine is designed to receive information from you in the form of recipes for the shape of the curve. You will find that by providing such information, it greatly adjusts the form of the result to match your knowledge of the process. Here I just made a few guesses about the shape of the curve from your comments.

In the above call, I gave the SLM command:

  • schedule the result
  • create a monotonic decreasing function x
  • Use 20 evenly spaced nodes.
  • make the curve have everywhere a positive second derivative
  • set the second derivatives at the end are zero

The plot as generated is gui itself, allowing you to build a function and data, as well as build derivatives of the result. The vertical green lines are the locations of the nodes.

curve and data

Here we see that matching a curve is a reasonable approximation to what you are looking for.

What about the second derived chart? Of course, SLM is a piecewise cubic tool. Therefore, the second derivatives are only piecewise linear. This is problem? Will you ask me to provide a tool for higher order splines? Sorry, but no, I won’t. These higher order derivatives are too poorly rated to require a very smooth result. In fact, I would be pleased with this prediction. Please note that the glitches in the second derivative were consistent. If I used more nodes or less, they were still there. This is a good way to find out if a shape is a curve shape or just an artifact of the placement of nodes.

See that the restrictions that I imposed on the shape of the curve led to the fact that it was quite reasonable, despite the fact that I used a lot more nodes than I had data. SLM did not have any problems in pricing.

2nd derivative

If I want to try a smoother estimate of the second derivative, just use more nodes. SLM is relatively fast. Thus, with 50 nodes, we get a very similar result for the second derivative of the curve.

2nd derivative, 50 knots

You can find SLM (here) on MATLAB Central. This requires an optimization toolbar.

+9
source

This is an extended comment, not an answer:

What do you know about the function that generates these points? If, for example, you have good reason to believe that it is a polynomial of degree 2, then the first step is to search for a polynomial of degree-2, which is best for your points, and then take the second derivative of it. If you think that a spline (of some kind) is the best description of f, then install a spline.

I don’t, and I’m not going to, I have built a graph of your function, so I’m not going to question the conjecture with which to start with a reasonable function.

If you do not have knowledge of the function, you can place any curve to give you the results that you like best - just do not forget that you have a second derivative of the function. You will have a second derivative of the function you selected, but you will no longer have knowledge of the 2nd derivative of the function that created your data than you did at the beginning.

+1
source

Source: https://habr.com/ru/post/1403852/


All Articles