Numerical first derivative of irregularly spaced data

7 Ansichten (letzte 30 Tage)
L'O.G. am 11 Dez. 2023
Kommentiert: Paul am 11 Dez. 2023
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.
0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J am 11 Dez. 2023
Bearbeitet: Matt J am 11 Dez. 2023
It seems to work:
t=sort( rand(1,1000)*2*pi );
I=1:20:1000;
plot(t,cos(t),'b--' , t(I), cos_t(I) ,'o'); legend('True','Finite Difference',Location='southeast')
6 Kommentare4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden
Star Strider am 11 Dez. 2023
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:
and:
now give the same result.
I wonder when the change occurred? It would be nice it that were added to the documentation.
Paul am 11 Dez. 2023
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Calendar finden Sie in Help Center und File Exchange

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by