%% Minimize with Extra Parameters
% Sometimes your objective function has extra parameters. These parameters are not variables to optimize, they are fixed values during the optimization. For example, suppose that you have a parameter a in the Rosenbrock-type function
%  f(x,a) = 100(x_2 - x_1^2)^2 + (a-x_1)^2.
% This function has a minimum value of 0 at x_1 = a, x_2 = a^2. If, for example, a = 3, you can include the parameter in your objective function by creating an anonymous function.
% Create the objective function with its extra parameters as extra arguments.

f = @(x,a)100*(x(2) - x(1)^2)^2 + (a-x(1))^2;

%
% Put the parameter in your MATLAB® workspace.

a = 3;

%
% Create an anonymous function of x alone that includes the workspace value of the parameter.

fun = @(x)f(x,a);

%
% Solve the problem starting at x0 = [-1,1.9].

x0 = [-1,1.9];
x = fminsearch(fun,x0)

% For more information about using extra parameters in your objective function, see Parameterizing Functions.
% Copyright 2012 The MathWorks, Inc.