Azzera filtri
Azzera filtri

diff vs. gradient

34 visualizzazioni (ultimi 30 giorni)
Benjamin
Benjamin il 5 Nov 2018
Modificato: Matt J il 5 Nov 2018
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

Risposta accettata

Matt J
Matt J il 5 Nov 2018
Modificato: Matt J il 5 Nov 2018
gradient uses central differences while diff(x) uses right-hand differences x(i+1)-x(i).
  12 Commenti
Star Strider
Star Strider il 5 Nov 2018
Yes!
Matt J
Matt J il 5 Nov 2018
Modificato: Matt J il 5 Nov 2018
If the X-data are not equi-spaced, use diff().

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by