diff vs. gradient

32 次查看(过去 30 天)
Benjamin
Benjamin 2018-11-5
编辑: Matt J 2018-11-5
Why does:
diffpressure = gradient(pressure)./gradient(density);
and
diffpressure = diff(pressure)./diff(density);
give drastically different results? The derivative using each method are completely different. See attached figure

采纳的回答

Matt J
Matt J 2018-11-5
编辑:Matt J 2018-11-5
gradient uses central differences while diff(x) uses right-hand differences x(i+1)-x(i).
  12 个评论
Matt J
Matt J 2018-11-5
编辑:Matt J 2018-11-5
If the X-data are not equi-spaced, use diff().

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by