请问各位朋友:谁有两阶段单纯形法的matlab程序,线形优化里两阶段单纯形法的matlab程序!但是我指的是用现有的函数,以及自己的语言实现!麻烦各位朋友了!

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/01 19:39:43
请问各位朋友:谁有两阶段单纯形法的matlab程序,线形优化里两阶段单纯形法的matlab程序!但是我指的是用现有的函数,以及自己的语言实现!麻烦各位朋友了!

请问各位朋友:谁有两阶段单纯形法的matlab程序,线形优化里两阶段单纯形法的matlab程序!但是我指的是用现有的函数,以及自己的语言实现!麻烦各位朋友了!
请问各位朋友:谁有两阶段单纯形法的matlab程序,
线形优化里两阶段单纯形法的matlab程序!
但是我指的是用现有的函数,以及自己的语言实现!麻烦各位朋友了!

请问各位朋友:谁有两阶段单纯形法的matlab程序,线形优化里两阶段单纯形法的matlab程序!但是我指的是用现有的函数,以及自己的语言实现!麻烦各位朋友了!
matlab自己就有啊!它是Nelder-Mead法或称下山单纯形法,由Nelder和Mead发现(1965年)
http://zhidao.baidu.com/question/18274859.html
>> type fminsearch
function [x,fval,exitflag,output] = fminsearch(funfcn,x,options,varargin)
%FMINSEARCH Multidimensional unconstrained nonlinear minimization (Nelder-Mead).
% X = FMINSEARCH(FUN,X0) starts at X0 and attempts to find a local minimizer
% X of the function FUN. FUN is a function handle. FUN accepts input X and
% returns a scalar function value F evaluated at X. X0 can be a scalar, vector
% or matrix.
%
% X = FMINSEARCH(FUN,X0,OPTIONS) minimizes with the default optimization
% parameters replaced by values in the structure OPTIONS, created
% with the OPTIMSET function. See OPTIMSET for details. FMINSEARCH uses
% these options: Display, TolX, TolFun, MaxFunEvals, MaxIter, FunValCheck,
% PlotFcns, and OutputFcn.
%
% X = FMINSEARCH(PROBLEM) finds the minimum for PROBLEM. PROBLEM is a
% structure with the function FUN in PROBLEM.objective, the start point
% in PROBLEM.x0, the options structure in PROBLEM.options, and solver
% name 'fminsearch' in PROBLEM.solver. The PROBLEM structure must have
% all the fields.
%
% [X,FVAL]= FMINSEARCH(...) returns the value of the objective function,
% described in FUN, at X.
%
% [X,FVAL,EXITFLAG] = FMINSEARCH(...) returns an EXITFLAG that describes
% the exit condition of FMINSEARCH. Possible values of EXITFLAG and the
% corresponding exit conditions are
%
% 1 Maximum coordinate difference between current best point and other
% points in simplex is less than or equal to TolX, and corresponding
% difference in function values is less than or equal to TolFun.
% 0 Maximum number of function evaluations or iterations reached.
% -1 Algorithm terminated by the output function.
%
% [X,FVAL,EXITFLAG,OUTPUT] = FMINSEARCH(...) returns a structure
% OUTPUT with the number of iterations taken in OUTPUT.iterations, the
% number of function evaluations in OUTPUT.funcCount, the algorithm name
% in OUTPUT.algorithm, and the exit message in OUTPUT.message.
%
% Examples
% FUN can be specified using @:
% X = fminsearch(@sin,3)
% finds a minimum of the SIN function near 3.
% In this case, SIN is a function that returns a scalar function value
% SIN evaluated at X.
%
% FUN can also be an anonymous function:
% X = fminsearch(@(x) norm(x),[1;2;3])
% returns a point near the minimizer [0;0;0].
%
% If FUN is parameterized, you can use anonymous functions to capture the
% problem-dependent parameters. Suppose you want to optimize the objective
% given in the function myfun, which is parameterized by its second argument c.
% Here myfun is an M-file function such as
%
% function f = myfun(x,c)
% f = x(1)^2 + c*x(2)^2;
%
% To optimize for a specific value of c, first assign the value to c. Then
% create a one-argument anonymous function that captures that value of c
% and calls myfun with two arguments. Finally, pass this anonymous function
% to FMINSEARCH:
%
% c = 1.5; % define parameter first
% x = fminsearch(@(x) myfun(x,c),[0.3;1])
%
% FMINSEARCH uses the Nelder-Mead simplex (direct search) method.
%
% See also OPTIMSET, FMINBND, FUNCTION_HANDLE.
% Reference: Jeffrey C. Lagarias, James A. Reeds, Margaret H. Wright,
% Paul E. Wright, "Convergence Properties of the Nelder-Mead Simplex
% Method in Low Dimensions", SIAM Journal of Optimization, 9(1):
% p.112-147, 1998.
% Copyright 1984-2006 The MathWorks, Inc.
% $Revision: 1.21.4.12.2.1 $ $Date: 2006/07/16 15:34:18 $
defaultopt = struct('Display','notify','MaxIter','200*numberOfVariables',...
'MaxFunEvals','200*numberOfVariables','TolX',1e-4,'TolFun',1e-4, ...
'FunValCheck','off','OutputFcn',[],'PlotFcns',[]);
% If just 'defaults' passed in, return the default options in X
if nargin==1 && nargout 0
disp(output.message)
end
return;
end
end
% Print out initial f(x) as 0th iteration
if prnt == 3
disp(' ')
disp(header)
disp(sprintf(' %5.0f %5.0f %12.6g %s', itercount, func_evals, fv(1), how));
elseif prnt == 4
clc
formatsave = get(0,{'format','formatspacing'});
format compact
format short e
disp(' ')
disp(how)
v
fv
func_evals
end
% OutputFcn and PlotFcns call
if haveoutputfcn || haveplotfcn
[xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'iter',itercount, ...
func_evals, how, fv(:,1),varargin{:});
if stop % Stop per user request.
[x,fval,exitflag,output] = cleanUpInterrupt(xOutputfcn,optimValues);
if prnt > 0
disp(output.message)
end
return;
end
end
% Continue setting up the initial simplex.
% Following improvement suggested by L.Pfeffer at Stanford
usual_delta = 0.05; % 5 percent deltas for non-zero terms
zero_term_delta = 0.00025; % Even smaller delta for zero elements of x
for j = 1:n
y = xin;
if y(j) ~= 0
y(j) = (1 + usual_delta)*y(j);
else
y(j) = zero_term_delta;
end
v(:,j+1) = y;
x(:) = y; f = funfcn(x,varargin{:});
fv(1,j+1) = f;
end
% sort so v(1,:) has the lowest function value
[fv,j] = sort(fv);
v = v(:,j);
how = 'initial simplex';
itercount = itercount + 1;
func_evals = n+1;
if prnt == 3
disp(sprintf(' %5.0f %5.0f %12.6g %s', itercount, func_evals, fv(1), how))
elseif prnt == 4
disp(' ')
disp(how)
v
fv
func_evals
end
% OutputFcn and PlotFcns call
if haveoutputfcn || haveplotfcn
[xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'iter',itercount, ...
func_evals, how, fv(:,1),varargin{:});
if stop % Stop per user request.
[x,fval,exitflag,output] = cleanUpInterrupt(xOutputfcn,optimValues);
if prnt > 0
disp(output.message)
end
return;
end
end
exitflag = 1;
% Main algorithm: iterate until
% (a) the maximum coordinate difference between the current best point and the
% other points in the simplex is less than or equal to TolX. Specifically,
% until max(||v2-v1||,||v2-v1||,...,||v(n+1)-v1||) = maxiter
msg = sprintf(['Exiting: Maximum number of iterations has been exceeded\n' ...
' - increase MaxIter option.\n' ...
' Current function value: %f \n'], fval);
if prnt > 0
disp(' ')
disp(msg)
end
exitflag = 0;
else
msg = ...
sprintf(['Optimization terminated:\n', ...
' the current x satisfies the termination criteria using OPTIONS.TolX of %e \n' ...
' and F(X) satisfies the convergence criteria using OPTIONS.TolFun of %e \n'], ...
tolx, tolf);
if prnt > 1
disp(' ')
disp(msg)
end
exitflag = 1;
end
output.message = msg;
%--------------------------------------------------------------------------
function [xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,x,xOutputfcn,state,iter,...
numf,how,f,varargin)
% CALLOUTPUTANDPLOTFCNS assigns values to the struct OptimValues and then calls the
% outputfcn/plotfcns.
%
% state - can have the values 'init','iter', or 'done'.
% For the 'done' state we do not check the value of 'stop' because the
% optimization is already done.
optimValues.iteration = iter;
optimValues.funccount = numf;
optimValues.fval = f;
optimValues.procedure = how;
xOutputfcn(:) = x; % Set x to have user expected size
% Call output functions
if ~isempty(outputfcn)
switch state
case {'iter','init'}
stop = callAllOptimOutputFcns(outputfcn,xOutputfcn,optimValues,state,varargin{:});
case 'done'
stop = false;
callAllOptimOutputFcns(outputfcn,xOutputfcn,optimValues,state,varargin{:});
otherwise
error('MATLAB:fminsearch:InvalidState', ...
'Unknown state in CALLOUTPUTANDPLOTFCNS.')
end
end
% Call plot functions
if ~isempty(plotfcns)
switch state
case {'iter','init'}
stop = callAllOptimPlotFcns(plotfcns,xOutputfcn,optimValues,state,varargin{:});
case 'done'
stop = false;
callAllOptimPlotFcns(plotfcns,xOutputfcn,optimValues,state,varargin{:});
otherwise
error('MATLAB:fminsearch:InvalidState', ...
'Unknown state in CALLOUTPUTANDPLOTFCNS.')
end
end
%--------------------------------------------------------------------------
function [x,FVAL,EXITFLAG,OUTPUT] = cleanUpInterrupt(xOutputfcn,optimValues)
% CLEANUPINTERRUPT updates or sets all the output arguments of FMINBND when the optimization
% is interrupted.
x = xOutputfcn;
FVAL = optimValues.fval;
EXITFLAG = -1;
OUTPUT.iterations = optimValues.iteration;
OUTPUT.funcCount = optimValues.funccount;
OUTPUT.algorithm = 'golden section search, parabolic interpolation';
OUTPUT.message = 'Optimization terminated prematurely by user.';
%--------------------------------------------------------------------------
function f = checkfun(x,userfcn,varargin)
% CHECKFUN checks for complex or NaN results from userfcn.
f = userfcn(x,varargin{:});
% Note: we do not check for Inf as FMINSEARCH handles it naturally.
if isnan(f)
error('MATLAB:fminsearch:checkfun:NaNFval', ...
'User function ''%s'' returned NaN when evaluated;\n FMINSEARCH cannot continue.', ...
localChar(userfcn));
elseif ~isreal(f)
error('MATLAB:fminsearch:checkfun:ComplexFval', ...
'User function ''%s'' returned a complex value when evaluated;\n FMINSEARCH cannot continue.', ...
localChar(userfcn));
end
%--------------------------------------------------------------------------
function strfcn = localChar(fcn)
% Convert the fcn to a string for printing
if ischar(fcn)
strfcn = fcn;
elseif isa(fcn,'inline')
strfcn = char(fcn);
elseif isa(fcn,'function_handle')
strfcn = func2str(fcn);
else
try
strfcn = char(fcn);
catch
strfcn = '(name not printable)';
end
end