What could be a faster way to calculate first derivative of a field?

1 vue (au cours des 30 derniers jours)
I want to calculate first derivative (using second-order FDM) of a 1D field that is quite large, about 12 million points. Instead of using:
for i = 2:(N-1)
dfdt(i) = (f(i+1)-f(i-1))/(2*dt);
end
can I do something else which takes advantage of some innate feature of MATLAB that could potentially reduce the total computational time?

Réponse acceptée

Bruno Luong
Bruno Luong le 31 Mar 2023
dfdt = (f(3:end)-f(1:end-2))*(1/(2*dt))

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by