Finding the highest and lowest point of a function

조회 수: 22 (최근 30일)
Reynand Joe
Reynand Joe 2023년 4월 24일
답변: Aditya Srikar 2023년 4월 28일
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
Rik
Rik 2023년 4월 24일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Aditya Srikar
Aditya Srikar 2023년 4월 28일
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 !

카테고리

Help CenterFile Exchange에서 Networks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by