Clear Filters
Clear Filters

Finding the highest and lowest point of a function

8 views (last 30 days)
Hi i want to ask about something, i want to solve and locate the highest and lowest points of a function using matlab gui but i dont know how to code it. The function is user defined and here is my code:
funcString = get(handles.edit1,'String');
funcHandle = str2func(['@(x)' funcString]);
x = linspace(10,-10,100);
y = funcHandle(x);
plot(handles.axes1,x,y);
please help
  1 Comment
Rik
Rik on 24 Apr 2023
What have you tried?
The obvious method of min and max will only work if your linspace happens to actually return the exact correct points, so you will need something smarter. Do you have the curve fitting toolbox? Otherwise you might be stuck with fminsearch.

Sign in to comment.

Answers (1)

Aditya Srikar
Aditya Srikar on 28 Apr 2023
Hi Joe
Let X represent a list of X-coordinates of all points of a curve.
Let Y represent a list of Y-coordinates of all points of a curve.
To obtain maximum value of Y-coordinate
Y1 = max(Y)
To obtain X-coordinate of point with maximum Y-coordinate value
X1 = X(find(Y == Y1))
To obtain minimum value of Y-coordinate
Y2 = min(Y)
To obtain X-coordinate od point with minimum Y-coordinate value
X2 = X(find(Y == Y2))
Hope it helps !

Categories

Find more on 2-D and 3-D 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!