Is there a way to directly take the second derivative of data?

48 ビュー (過去 30 日間)
Benjamin
Benjamin 2018 年 11 月 15 日
コメント済み: Benjamin 2018 年 11 月 19 日
In MATLAB, can I take the second derivative of data directly? Or do I need to take the derivative first using gradient, and then take the derivative of that. I am worried I am losing some precision each time, and wondering if I could go straight from y to y''.

回答 (2 件)

John D'Errico
John D'Errico 2018 年 11 月 15 日
編集済み: John D'Errico 2018 年 11 月 16 日
Well, even gradient or diff does not actually differentiate data. They can give you an approximation to the derivative at each data point.
And, yes, you are correct to fear multiple sequential calls to gradient, as it is anapproximation at each step. The problem with numerical differentiation is it is a noise amplifiying process, sometimes called an ill-posed problem.
You don't tell us enough about your problem that I can be sure about the best approach. Is your data equally spaced in x? Is there noise in the process? This makes things more difficult.
There are several ideas you could use. I'd suggest that perhaps a Savitsky-Golay filter might be a good idea, if there is noise, and if the data is uniform in x. Or perhaps if there is no noise, then you might pass an interpolating spline through the points, then differentiate the spline twice, evaluating it at the points. Since you are looking for a second derivative, I'd probably suggest a quintic spline as a good idea. Or if there is noise in the data, then asmoothing or least squares spline canbe of value. Again, you would differentiate it at the end, and you would not incur the cost of recursive numerical differentiation.
If you truly want better advice, I would need to know more about the data, and your problem, as well as have you attach a copy of the data.
  1 件のコメント
Benjamin
Benjamin 2018 年 11 月 19 日
John,
Thank you for your detailed answer. Can you explain what you mean when you say that gradient does not actually differentiate the data? How is gradient calculating it then? And how is it different than diff?
For my problem speciically, the data is evenly spaced in x, and there is not a lot of noise. I was thinking maybe I should calculate my derivatives differently. How would I use a quintic spline?

サインインしてコメントする。


Jim Riggs
Jim Riggs 2018 年 11 月 16 日
編集済み: Jim Riggs 2018 年 11 月 16 日
Here are some formulas that I sometimes use:
Everything that John says about data smoothing and noise still applies.

カテゴリ

Help Center および File ExchangeSpline Postprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by