How do I take the derivative of my plot?
Show older comments
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?
Accepted Answer
More Answers (1)
Shaun VanWeelden
on 19 Apr 2013
2 votes
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 Comment
John D'Errico
on 31 Jul 2016
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).
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!