filtering by the second derivative?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Steve Miller
il 6 Gen 2020
Commentato: Walter Roberson
il 6 Gen 2020
I have an array, and I'm trying to figure out how to mark the values where the second derivative is above a threshold. To get the second derivative I'm doing
diff(diff(array)), the problem is that creates a result of length(array)-2, and I want to created a logical array for the original array.
For example, with
arr = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34];
and a filter of x < 2, I'd like to produce:
[1,1,1,1,1,1,1,0,0,0]
since the second derivative is
[-1,1,0,1,1,2,3,5]
Hopefully that makes sense.
0 Commenti
Risposta accettata
Walter Roberson
il 6 Gen 2020
gradient(gradient(arr)) < 2
Watch out for < 2 compared to <= 2
2 Commenti
Walter Roberson
il 6 Gen 2020
Well, then, you are stuck. diff() will never return an array of full size equal to its input (except in the degenerate case diff([]) in which case the result is [] which is equal in size to the input.) Therefore if you define taking the derivative as using diff(), then you have boxed yourself into a corner.
Mathematically, diff() is only one way among several to numerically estimate derivative. It is not considered to be the best numeric derivative because at any one point, it is only using two adjacent points to do the estimate, instead of using points before and after to do the estimation. https://en.wikipedia.org/wiki/Finite_difference
gradient() uses central difference except at the two edges. Central difference is often considered a closer numeric approximation to derivative than what is used by diff()
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!