开发者

Numerical Differentiation of List in Mathematica

开发者 https://www.devze.com 2023-03-15 16:24 出处:网络
How do I numerically differentiate a list in Mathematica without first fitting it to a mathematical expression (ie. using FindFit)?

How do I numerically differentiate a list in Mathematica without first fitting it to a mathematical expression (ie. using FindFit)?

Specifically, I would like to find the point of maximum slope in the list.

I have considered using Differences and finding the maximum difference, but noise in the data renders that inaccurate. Smoothing the dat开发者_如何学JAVAa with MovingAverage does not help either.

Thanks in advance.


You could try a ListConvolve with a Gaussian kernel to smooth your data. One of the nice features of this is that the derivative of the convolution with a Gaussian kernel is equivalent to convolving with a derivative of the Gaussian kernel.

Here is some sample data:

data = Table[Sin[x] + .5 RandomReal[{-1, 1}], {x, 0, 6 \[Pi], .05}];
ListLinePlot[data]

Numerical Differentiation of List in Mathematica

This is a simple convolution with a Gaussian kernel:

data2 = 
  Block[{\[Sigma] = 2}, 
   ListConvolve[
    Table[1/(Sqrt[2 \[Pi]] \[Sigma]) E^(-x^2/(2 \[Sigma])), 
         {x, -2 , 2, 1/10}
    ], data, {11, 11}
   ]
  ];  
ListLinePlot[data2]

Numerical Differentiation of List in Mathematica

Convolution with the first derivative of a Gaussian:

data3 = 
  Block[{\[Sigma] = 1}, 
   ListConvolve[
    Table[-((E^(-(x^2/(2 \[Sigma]))) x)/(Sqrt[2 \[Pi]] \[Sigma]^2)), 
      {x, -2 \[Sigma],2 \[Sigma], \[Sigma]/10}
    ], data, {11, 11}
   ]
  ];
ListLinePlot[data3]

Numerical Differentiation of List in Mathematica

You may want to play with the sigma parameter to see what gets optimal results in your case.

The whole theory behind this is called Scale Space. Note that the above statement about convolution holds for continuous space. For a discrete implementation, the kernel could be chosen somewhat better.

Note further that, just as MovingAverage, a convolution can move the features of your data.

0

精彩评论

暂无评论...
验证码 换一张
取 消