diff vs. gradient

68 ビュー (過去 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 件のコメント
Star Strider
Star Strider 2018 年 11 月 5 日
Yes!
Matt J
Matt J 2018 年 11 月 5 日
編集済み: Matt J 2018 年 11 月 5 日
If the X-data are not equi-spaced, use diff().

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying 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