Is there a way to find slope at any point on the graph?

I have plotted a graph (I-V curve of transistor) and I need to find slope at various points as encircled. What is the way to do so? Thanks, Kany

 Respuesta aceptada

Star Strider
Star Strider el 9 de Abr. de 2015
The easiest way is to use the gradient function. (I believe you forgot to upload your plot, but that doesn’t affect my Answer.)
If you then want the slope at particular values of your x-variable, use the find function to detect the indices of those values, then use the indices to find the value of the gradient at those values.

4 comentarios

kanyvt
kanyvt el 9 de Abr. de 2015
Thanks for your reply. But I was wondering if I can find the slope by using Diff command. I don't clearly understand the difference between Diff and gradient function.
My pleasure.
I would not use diff to take a numerical derivative. It has its uses, but there are significant advantages to using gradient to get the derivative, the most obvious one being that the resulting vector is the same length as the argument vector. The gradient function assumes that the independent variable is regularly sampled, and uses a constant difference to calculate the derivative. The diff function (as ‘dydx=diff(y)./diff(x)’) does not, but the result of diff is one element shorter than the argument vector. So depending on your needs, one may be better than the other.
I routinely use gradient for numerical derivatives, and diff if I want to explore discontinuities and other such properties of data vectors.
kanyvt
kanyvt el 9 de Abr. de 2015
Yeah you are right, the length is same in the gradient vector. But the problem is how to verify which way of finding slope is correct ? Sometimes the results from gradient function and diff function vary a lot.
If you have constant, equal spacing of your independent variable, gradient is preferable. If you have unequal independent variable spacing, diff may be more accurate in some situations.
However, you can convert unequal spacing to equal spacing with the interp1 function. So it would likely be easier and more accurate to define equally-spaced independent variable values and interpolate their corresponding dependent variable values with interp1 and use gradient for the derivative, remembering to define the independent variable constant spacing interval in your call to gradient.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 9 de Abr. de 2015

Comentada:

el 9 de Abr. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by