Effacer les filtres
Effacer les filtres

Finding the highest and lowest point of a function

8 vues (au cours des 30 derniers jours)
Reynand Joe
Reynand Joe le 24 Avr 2023
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 commentaire
Rik
Rik le 24 Avr 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.

Connectez-vous pour commenter.

Réponses (1)

Aditya Srikar
Aditya Srikar le 28 Avr 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 !

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by