Alternatives to using diff(X,2)

조회 수: 1 (최근 30일)
AtoZ
AtoZ 2018년 12월 8일
댓글: Bruno Luong 2018년 12월 8일
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.

채택된 답변

Bruno Luong
Bruno Luong 2018년 12월 8일
편집: Bruno Luong 2018년 12월 8일
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
AtoZ
AtoZ 2018년 12월 8일
편집: AtoZ 2018년 12월 8일
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 2018년 12월 8일
No this is numerical difference method

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

태그

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by