How do I take the derivative of my plot?
조회 수: 260 (최근 30일)
이전 댓글 표시
I have my temperature in the y axis, and my distance in the x. I have them all plotted out and I have the data too, how can I take the derivative of the plot?
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2013년 4월 19일
dy=diff(y)./diff(x)
plot(x(2:end),dy)
댓글 수: 8
Ali
2023년 1월 23일
does that work when the derivative at some data points has 2 values (before and after the data point)?
I mean the derivative of the plot is not continuous in all points.
Torsten
2023년 1월 23일
편집: Torsten
2023년 1월 23일
If you only have discrete values for x and y, there is no method to tell you whether there is a discontinuity in the derivative of y in a point x_i.
You can compare (y(i+1)-y(i))/(x(i+1)-x(i)) with (y(i)-y(i-1))/(x(i)-x(i-1)), but even if both differ significantly, it's not possible to decide whether there is a discontinuity in the derivative at x=x(i).
추가 답변 (1개)
Shaun VanWeelden
2013년 4월 19일
Call polyfit to generate your polynomial (if you don't already have a polynomial)
Call polyder to get derivative of your fitted line
Call polyval with your original X values to get the Y values of your derivative and plot that with hold on so it doesn't erase your original plot
댓글 수: 1
John D'Errico
2016년 7월 31일
Note that polyfit (any polynomial fit) will often be a terribly poor choice here, since many curves are not well fit by a polynomial model. For example, consider points that lie on the perimeter of a circle, or the function sqrt(x), near x==0. Or the function sin(x), over multiple periods. Or a classic problem function for polynomial fits, 1/(1+x^2).
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!