필터 지우기
필터 지우기

Numerical first derivative of irregularly spaced data

조회 수: 14 (최근 30일)
L'O.G.
L'O.G. 2023년 12월 11일
댓글: Paul 2023년 12월 11일
Given a vector x and a vector y, the numerical first derivative should be gradient(y)./gradient(x) for all points specified by x, right? Is that the case even if the vector x is irregularly spaced? (If not, how do you do so?) Also, which finite differences method does this use? Thanks.

채택된 답변

Matt J
Matt J 2023년 12월 11일
편집: Matt J 2023년 12월 11일
It seems to work:
t=sort( rand(1,1000)*2*pi );
cos_t=gradient(sin(t))./gradient(t);
I=1:20:1000;
plot(t,cos(t),'b--' , t(I), cos_t(I) ,'o'); legend('True','Finite Difference',Location='southeast')
  댓글 수: 6
Star Strider
Star Strider 2023년 12월 11일
The single gradient call using both vectors is new, and does not appear to be documented as a change.
In earlier versions (perhaps as recently as five years ago), gradient used the first element of the second argument vector (or perhaps the difference between the first and second elements), giving anomalous results. That required dividing the gradient of the dependent variable vector by the gradient of the independent variable vector to get an acceptable result. I just now compared them (using a vector that was not close to being regularly-spaced), and it appears to consider the entire vector, since:
gradient(x,t)
and:
gradient(x) ./ gradient(t)
now give the same result.
I wonder when the change occurred? It would be nice it that were added to the documentation.
Paul
Paul 2023년 12월 11일
The issue I was trying to illustrate wasn't with the accuracy of the estimated gradiient, rather with the pointwise mapping of each gradient estimate to a value of the independent variable.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by