📄 fminsearch.cpp
字号:
fv = sort(&j, fv);
//
// v = v(:,j);
//
v = v(colon(), j);
//
// itercount = itercount + 1;
//
itercount = itercount + mwArray(1.0);
//
// if prnt == 2
//
if (tobool(prnt == mwArray(2.0))) {
//
// disp([sprintf(' %5.0f %5.0f %12.6g ', itercount, func_evals, fv(1)), how])
//
disp(
horzcat(
mwVarargin(
sprintf(
mwArray(" %5.0f %5.0f %12.6g "),
mwVarargin(itercount, func_evals, fv(1.0))),
how)));
//
// elseif prnt == 3
//
} else if (tobool(prnt == mwArray(3.0))) {
//
// disp(' ')
//
disp(" ");
//
// disp(how)
//
disp(how);
//
// v
//
v.Print("v");
//
// fv
//
fv.Print("fv");
//
// func_evals
//
func_evals.Print("func_evals");
//
// end
//
}
//
// end % while
//
}
//
//
//
// x(:) = v(:,1);
//
x(colon()) = v(colon(), 1.0);
//
// if prnt == 3,
//
if (tobool(prnt == mwArray(3.0))) {
//
// % reset format
// set(0,{'format','formatspacing'},formatsave);
//
ans
= set(
mwVarargin(
0.0,
cellhcat(mwVarargin("format", "formatspacing")),
formatsave));
//
// end
//
}
//
// output.iterations = itercount;
//
(*output).field("iterations") = itercount;
//
// output.funcCount = func_evals;
//
(*output).field("funcCount") = func_evals;
//
// output.algorithm = 'Nelder-Mead simplex direct search';
//
(*output).field("algorithm") = "Nelder-Mead simplex direct search";
//
//
// fval = min(fv);
//
*fval = min(fv);
//
// if func_evals >= maxfun
//
if (tobool(func_evals >= maxfun)) {
//
// if prnt > 0
//
if (tobool(prnt > mwArray(0.0))) {
//
// disp(' ')
//
disp(" ");
//
// disp('Exiting: Maximum number of function evaluations has been exceeded')
//
disp(
"Exiting: Maximum number of functio"
"n evaluations has been exceeded");
//
// disp(' - increase MaxFunEvals option.')
//
disp(" - increase MaxFunEvals option.");
//
// msg = sprintf(' Current function value: %f \n', fval);
//
msg
= sprintf(
mwArray(" Current function value: %f \\n"),
mwVarargin(*fval));
//
// disp(msg)
//
disp(msg);
//
// end
//
}
//
// exitflag = 0;
//
*exitflag = 0.0;
//
// elseif itercount >= maxiter
//
} else if (tobool(itercount >= maxiter)) {
//
// if prnt > 0
//
if (tobool(prnt > mwArray(0.0))) {
//
// disp(' ')
//
disp(" ");
//
// disp('Exiting: Maximum number of iterations has been exceeded')
//
disp("Exiting: Maximum number of iterations has been exceeded");
//
// disp(' - increase MaxIter option.')
//
disp(" - increase MaxIter option.");
//
// msg = sprintf(' Current function value: %f \n', fval);
//
msg
= sprintf(
mwArray(" Current function value: %f \\n"),
mwVarargin(*fval));
//
// disp(msg)
//
disp(msg);
//
// end
//
}
//
// exitflag = 0;
//
*exitflag = 0.0;
//
// else
//
} else {
//
// if prnt > 0
//
if (tobool(prnt > mwArray(0.0))) {
//
// convmsg1 = sprintf([ ...
//
convmsg1
= sprintf(
vertcat(
mwVarargin(
horzcat(
mwVarargin(
"\\nOptimization terminated successfully:\\n",
" the current x satisfies the termination"
" criteria using OPTIONS.TolX of %e \\n",
" and F(X) satisfies the convergence cri"
"teria using OPTIONS.TolFun of %e \\n")),
empty())),
mwVarargin(options.field("TolX"), options.field("TolFun")));
//
// '\nOptimization terminated successfully:\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'
// ],options.TolX, options.TolFun);
// disp(convmsg1)
//
disp(convmsg1);
//
// exitflag = 1;
//
*exitflag = 1.0;
//
// end
//
}
//
// end
//
}
//
//
//
//
//
//
return_:
mwValidateOutputs("fminsearch", 4, nargout_, &x, fval, exitflag, output);
return x;
}
//
// The function "Nfminsearch" contains the nargout interface for the
// "fminsearch" M-function from file
// "D:\MATLABR11\toolbox\matlab\funfun\fminsearch.m" (lines 1-280). This
// interface is only produced if the M-function uses the special variable
// "nargout". The nargout interface allows the number of requested outputs to
// be specified via the nargout argument, as opposed to the normal interface
// which dynamically calculates the number of outputs based on the number of
// non-NULL inputs it receives. This function processes any input arguments and
// passes them to the implementation version of the function, appearing above.
//
mwArray Nfminsearch(int nargout,
mwArray * fval,
mwArray * exitflag,
mwArray * output,
mwArray funfcn,
mwArray x_,
mwArray options,
mwVarargin varargin) {
mwArray x(mclGetUninitializedArray());
mwArray fval__(mclGetUninitializedArray());
mwArray exitflag__(mclGetUninitializedArray());
mwArray output__(mclGetUninitializedArray());
x
= Mfminsearch(
&fval__,
&exitflag__,
&output__,
nargout,
funfcn,
x_,
options,
varargin.ToArray());
if (fval != NULL) {
(*fval).CopyOutputArg(fval__);
}
if (exitflag != NULL) {
(*exitflag).CopyOutputArg(exitflag__);
}
if (output != NULL) {
(*output).CopyOutputArg(output__);
}
return x;
}
//
// The function "fminsearch" contains the normal interface for the "fminsearch"
// M-function from file "D:\MATLABR11\toolbox\matlab\funfun\fminsearch.m"
// (lines 1-280). This function processes any input arguments and passes them
// to the implementation version of the function, appearing above.
//
mwArray fminsearch(mwArray * fval,
mwArray * exitflag,
mwArray * output,
mwArray funfcn,
mwArray x_,
mwArray options,
mwVarargin varargin) {
int nargout(1);
mwArray x(mclGetUninitializedArray());
mwArray fval__(mclGetUninitializedArray());
mwArray exitflag__(mclGetUninitializedArray());
mwArray output__(mclGetUninitializedArray());
if (fval != NULL) {
++nargout;
}
if (exitflag != NULL) {
++nargout;
}
if (output != NULL) {
++nargout;
}
x
= Mfminsearch(
&fval__,
&exitflag__,
&output__,
nargout,
funfcn,
x_,
options,
varargin.ToArray());
if (fval != NULL) {
(*fval).CopyOutputArg(fval__);
}
if (exitflag != NULL) {
(*exitflag).CopyOutputArg(exitflag__);
}
if (output != NULL) {
(*output).CopyOutputArg(output__);
}
return x;
}
//
// The function "Vfminsearch" contains the void interface for the "fminsearch"
// M-function from file "D:\MATLABR11\toolbox\matlab\funfun\fminsearch.m"
// (lines 1-280). The void interface is only produced if the M-function uses
// the special variable "nargout", and has at least one output. The void
// interface function specifies zero output arguments to the implementation
// version of the function, and in the event that the implementation version
// still returns an output (which, in MATLAB, would be assigned to the "ans"
// variable), it deallocates the output. This function processes any input
// arguments and passes them to the implementation version of the function,
// appearing above.
//
void Vfminsearch(mwArray funfcn,
mwArray x_,
mwArray options,
mwVarargin varargin) {
mwArray x(mwArray::UNASSIGNED);
mwArray fval(mwArray::UNASSIGNED);
mwArray exitflag(mwArray::UNASSIGNED);
mwArray output(mwArray::UNASSIGNED);
x
= Mfminsearch(
&fval,
&exitflag,
&output,
0,
funfcn,
x_,
options,
varargin.ToArray());
}
//
// The function "mlxFminsearch" contains the feval interface for the
// "fminsearch" M-function from file
// "D:\MATLABR11\toolbox\matlab\funfun\fminsearch.m" (lines 1-280). The feval
// function calls the implementation version of fminsearch through this
// function. This function processes any input arguments and passes them to the
// implementation version of the function, appearing above.
//
void mlxFminsearch(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
MW_BEGIN_MLX();
{
mwArray mprhs[4];
mwArray mplhs[4];
int i;
if (nlhs > 4) {
error(
"Run-time Error: File: fminsearch Line: 1 Column"
": 0 The function \"fminsearch\" was called with"
" more than the declared number of outputs (4)");
}
for (i = 0; i < 3 && i < nrhs; ++i) {
mprhs[i] = mwArray(prhs[i], 0);
}
for (; i < 3; ++i) {
mprhs[i].MakeDIN();
}
mprhs[3] = mclCreateVararginCell(nrhs - 3, prhs + 3);
mplhs[0]
= Mfminsearch(
&mplhs[1],
&mplhs[2],
&mplhs[3],
nlhs,
mprhs[0],
mprhs[1],
mprhs[2],
mprhs[3]);
plhs[0] = mplhs[0].FreezeData();
for (i = 1; i < 4 && i < nlhs; ++i) {
plhs[i] = mplhs[i].FreezeData();
}
}
MW_END_MLX();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -