>> help fminunc FMINUNC Finds the minimum of a function of several variables. X=FMINUNC(FUN,X0) starts at X0 and finds a minimum X of the function FUN. FUN accepts input X and returns a scalar function value F evaluated at X. X0 can be a scalar, vector or matrix. X=FMINUNC(FUN,X0,OPTIONS) minimizes with the default optimization parameters replaced by values in the structure OPTIONS, an argument created with the OPTIMSET function. See OPTIMSET for details. Used options are Display, TolX, TolFun, DerivativeCheck, Diagnostics, GradObj, HessPattern, LineSearchType, Hessian, HessMult, HessUpdate, MaxFunEvals, MaxIter, DiffMinChange and DiffMaxChange, LargeScale, MaxPCGIter, PrecondBandWidth, TolPCG, TypicalX. Use the GradObj option to specify that FUN also returns a second output argument G that is the partial derivatives of the function df/dX, at the point X. Use the Hessian option to specify that FUN also returns a third output argument H that is the 2nd partial derivatives of the function (the Hessian) at the point X. The Hessian is only used by the large-scale method, not the line-search method. X=FMINUNC(FUN,X0,OPTIONS,P1,P2,...) passes the problem-dependent parameters P1,P2,... directly to the function FUN, e.g. FUN would be called using feval as in: feval(FUN,X,P1,P2,...). Pass an empty matrix for OPTIONS to use the default values. [X,FVAL]=FMINUNC(FUN,X0,...) returns the value of the objective function FUN at the solution X. [X,FVAL,EXITFLAG]=FMINUNC(FUN,X0,...) returns a string EXITFLAG that describes the exit condition of FMINUNC. If EXITFLAG is: > 0 then FMINUNC converged to a solution X. 0 then the maximum number of function evaluations was reached. < 0 then FMINUNC did not converge to a solution. [X,FVAL,EXITFLAG,OUTPUT]=FMINUNC(FUN,X0,...) returns a structure OUTPUT with the number of iterations taken in OUTPUT.iterations, the number of function evaluations in OUTPUT.funcCount, the algorithm used in OUTPUT.algorithm, the number of CG iterations (if used) in OUTPUT.cgiterations, and the first-order optimality (if used) in OUTPUT.firstorderopt. [X,FVAL,EXITFLAG,OUTPUT,GRAD]=FMINUNC(FUN,X0,...) returns the value of the gradient of FUN at the solution X. [X,FVAL,EXITFLAG,OUTPUT,GRAD,HESSIAN]=FMINUNC(FUN,X0,...) returns the value of the Hessian of the objective function FUN at the solution X. Examples FUN can be specified using @: X = fminunc(@myfun,2) where MYFUN is a MATLAB function such as: function F = myfun(x) F = sin(x) + 3; To minimize this function with the gradient provided, modify the MYFUN so the gradient is the second output argument: function [f,g]= myfun(x) f = sin(x) + 3; g = cos(x); and indicate the gradient value is available by creating an options structure with OPTIONS.GradObj set to 'on' (using OPTIMSET): options = optimset('GradObj','on'); x = fminunc('myfun',4,options); FUN can also be an inline object: x = fminunc(inline('sin(x)+3'),4); See also OPTIMSET, FMINSEARCH, FMINBND, FMINCON, @, INLINE.