Label Root of Function on Graph - Matlab Help

  • Context: MATLAB 
  • Thread starter Thread starter .ryan.
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

This discussion focuses on labeling the roots of a function on a graph using MATLAB. The user seeks syntax guidance and is provided with a method to find and plot roots. The suggested approach involves using the find function to identify roots based on the condition abs(y) <= eps or abs(y) == min(abs(y)). The final plotting command combines the original plot with markers for the roots using plot and label.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of plotting in MATLAB
  • Basic knowledge of numerical methods for root finding
  • Concept of absolute error in numerical analysis
NEXT STEPS
  • Learn MATLAB's find function for indexing
  • Explore MATLAB's plotting functions, specifically plot and label
  • Study numerical methods for root finding, such as the bisection method
  • Investigate MATLAB's documentation on graphical annotations
USEFUL FOR

Mathematics students, engineers, and data analysts who utilize MATLAB for graphing functions and require assistance in visualizing roots on plots.

.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
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K