MATLAB Label Root of Function on Graph - Matlab Help

  • Thread starter Thread starter .ryan.
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
To label the root of a function on a graph in Matlab, first identify the roots using the command `roots = find(abs(y) <= eps)` or `roots = find(abs(y) == min(abs(y)))` if there is a single root. This will provide the indices of the roots in the y vector. Next, plot the function using `plot(t, y, t(roots), y(roots), '*')` to visualize the function alongside the roots, which are marked with stars. Finally, use `label('y', 'roots')` to label the graph appropriately. This method effectively highlights the roots on the plot, although there may be alternative approaches available.
.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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K