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

2 views (last 30 days)
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?

Accepted Answer

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

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!