Label Root of Function on Graph - Matlab Help

  • Context: MATLAB 
  • Thread starter Thread starter .ryan.
  • Start date Start date
  • Tags Tags
    Matlab
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 4K views
.ryan.
Messages
14
Reaction score
0
Hey guys. Can someone help me with the syntax needed to label the root of a function on a graph, using Matlab? I've used the help function, but I couldn't find anything that was effective. Thanks.
 
Physics news on Phys.org
.ryan. said:
Hey guys. Can someone help me with the syntax needed to label the root of a function on a graph, using Matlab? I've used the help function, but I couldn't find anything that was effective. Thanks.

I'm not sure if there's a way to make Matlab find and label roots on a plot, but you can make it find them separately and plot that point on the plot.

For example, if you are plotting y vs. t and want to find the roots of y, you can do
roots = find(abs(y)<=eps)
(or roots = find(abs(y) == min(abs(y))) if you know there's only one root). This finds the indices in the y vector corresponding to (approximately) the roots of y.

Then you can do
plot(t,y,t(roots),y(roots),'*');label('y','roots')
to plot y vs. t, and then on top of that it plots stars on the points where you found roots. There may be better ways but that's the best thing I can think of off hand.