doing derivative using diff(Y)/dT makes the vector shorter
Ältere Kommentare anzeigen
Hi everybody,
I'm doing derivative of a curve Y-T I think it's:
T = linspace(-t, t, n); Y = somefuction; dT = T(2)-T(1); DY1 = diff(Y)/dT;
But then DY1 is one element shorter than Y. How do people usually deal with this?
I'm currently dealing with this by shorten the T axis:
plot( T(1:end-1), DY1 );
I don't know whether this is the best way... Is there are relative standard way? Let me know. Thanks everyone~
Akzeptierte Antwort
Weitere Antworten (2)
Azzi Abdelmalek
am 14 Jun. 2013
Bearbeitet: Azzi Abdelmalek
am 14 Jun. 2013
Edit
(x(2)-x(1))/(t(2)-t(1)) correspond to the approximative right derivative at the point(t(1),x(1)). The last point is (t(n-1),x(n-1)), which means that you are doing right
1 Kommentar
Yuji Zhang
am 15 Jun. 2013
Iain
am 14 Jun. 2013
How I normally do it:
average_slope_between_y1_and_y2 = diff(Y)./diff(t);
middle_of_the_time_between_y1_and_y2 = (t(2:end)+t(1:end-1))./2;
Alternatively, fit a curve to your data, and differentiate that.
3 Kommentare
Yuji Zhang
am 15 Jun. 2013
Iain
am 15 Jun. 2013
Two consecutive points on your curve "y" :P
Maybe I should have them put my name in all caps...
Felipe Padua
am 12 Okt. 2021
You could also use
middle_of_the_time_between_y1_and_y2 = movemean(t, 2, 'endpoints', 'discard')
Kategorien
Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!