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

    %% Minimize Rosenbrock's Function
% Minimize Rosenbrock's function, a notoriously difficult optimization
% problem for many algorithms:
%
% $$f(x) = 100(x_2 - x_1^2)^2 + (1 - x_1)^2.$$
%
% The function is minimized at the point |x = [1,1]| with minimum value
% |0|.
%%
% Set the start point to |x0 = [-1.2,1]| and minimize Rosenbrock's
% function using |fminsearch|.

fun = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
x0 = [-1.2,1];
x = fminsearch(fun,x0)