www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/HumpsPlotExample.m

    %% Minimizing Functions of One Variable
% Given a mathematical function of a single variable, you can use the
% |fminbnd| function to find a local minimizer of the function in a given
% interval. For example, consider the |humps.m| function, which is provided
% with MATLAB(R).

% Copyright 2015 The MathWorks, Inc.


%% Plot of the humps function
%
x = -1:.01:2;
y = humps(x);
plot(x,y)
xlabel('x')
ylabel('humps(x)')
grid on
%% Minimize the humps function
% To find the minimum of the |humps| function in the range |(0.3,1)|, use
x = fminbnd(@humps,0.3,1)
%%
% You can ask for a tabular display of output by passing a fourth argument
% created by the |optimset| command to |fminbnd|:
opts = optimset('Display','iter');
x = fminbnd(@humps,0.3,1,opts)