Borrar filtros
Borrar filtros

Finding the highest and lowest point of a function

6 visualizaciones (últimos 30 días)
Reynand Joe
Reynand Joe el 24 de Abr. de 2023
Respondida: Aditya Srikar el 28 de Abr. de 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 comentario
Rik
Rik el 24 de Abr. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Aditya Srikar
Aditya Srikar el 28 de Abr. de 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 !

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by