Effacer les filtres
Effacer les filtres

Alternatives to using diff(X,2)

1 vue (au cours des 30 derniers jours)
AtoZ
AtoZ le 8 Déc 2018
Commenté : Bruno Luong le 8 Déc 2018
Just a simple question:
We have an alternative for the opreation diff(A,1) given by A(2:end)-A(1:end-1), from an earlier post.
How to generalize it for diff(A,2)? for say A=[1 2 3 4 5 6]? to get [0 0 0 0].
Thanks.

Réponse acceptée

Bruno Luong
Bruno Luong le 8 Déc 2018
Modifié(e) : Bruno Luong le 8 Déc 2018
Just apply the same method twice
D1 = A(2:end)-A(1:end-1);
D2 = D1(2:end)-D1(1:end-1)
or
D2 = conv(A,[1 -2 1],'valid')
  3 commentaires
AtoZ
AtoZ le 8 Déc 2018
Modifié(e) : AtoZ le 8 Déc 2018
Does it also work for sym type inputs? the conv(..) thing gives error for sym type input while the D2 prescription works.
Bruno Luong
Bruno Luong le 8 Déc 2018
No this is numerical difference method

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange

Produits


Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by