Locating max/min of 3d surface

5 次查看(过去 30 天)
How could I go about locating the global min/max of a user input function. The GUI plots a function based on user input:
% Get the function
g=get(handles.funcxy,'String');
% Get the x limits
limit=[str2num(char(get(handles.xmin,'String'))),... str2num(char(get(handles.xmax,'String')))];
% Convert to inline for plotting
func=inline(char(g));
% Set axes to draw on
axes(handles.plot);
% Plot the surface defined by a function f(x,y)=func
ezsurf(func,limit);
I have figured out in order to find the z maximum I can do
sh=ezsurf(func,limit);
setappdata(0, 'function', char(g));
zd=get(sh,'zdata');
zmax=max(max(zd));
But how can I get the corresponding x,y points

采纳的回答

Jared
Jared 2011-11-27
I found the answer myself so I figured I might as well post the solution for anyone else.
sh=ezsurf(func,limit);
zd=get(sh,'zdata');
xd=get(sh,'xdata');
yd=get(sh,'ydata');
% Construct 3xa matrix of data points (X,Y,Zmax)
while a<=size(i,1)
A(1,a)=xd(i(a));
A(2,a)=yd(i(a));
A(3,a)=zmax;
a=a+1;
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by