⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lsqnonlin.c

📁 ASUFIT-Matlab-全局拟合程序
💻 C
📖 第 1 页 / 共 5 页
字号:
         */
        } else if (mclSwitchCompare(t_, mxCreateString("iter"))) {
            /*
             * verbosity = 2;
             */
            mlfAssign(&verbosity, mlfScalar(2.0));
        /*
         * case 'final'
         */
        } else if (mclSwitchCompare(t_, mxCreateString("final"))) {
            /*
             * verbosity = 1;
             */
            mlfAssign(&verbosity, mlfScalar(1.0));
        /*
         * case 'testing'
         */
        } else if (mclSwitchCompare(t_, mxCreateString("testing"))) {
            /*
             * verbosity = Inf;
             */
            mlfAssign(&verbosity, mlfInf());
        /*
         * otherwise
         */
        } else {
            /*
             * verbosity = 1;
             */
            mlfAssign(&verbosity, mlfScalar(1.0));
        /*
         * end
         */
        }
        mxDestroyArray(t_);
    }
    /*
     * 
     * [xstart,l,u,msg] = checkbounds(xstart,LB,UB,numberOfVariables);
     */
    mlfAssign(
      &xstart,
      mlfOptim_private_checkbounds(
        &l, &u, &msg, xstart, LB, UB, numberOfVariables));
    /*
     * if ~isempty(msg)
     */
    if (mlfTobool(mlfNot(mlfIsempty(msg)))) {
        /*
         * EXITFLAG = -1;
         */
        mlfAssign(EXITFLAG, mlfScalar(-1.0));
        /*
         * [Resnorm,FVAL,OUTPUT,LAMBDA,JACOB] = deal([]);
         */
        mlfNDeal(
          0,
          mlfVarargout(Resnorm, FVAL, OUTPUT, LAMBDA, JACOB, NULL),
          mclCreateEmptyArray(),
          NULL);
        /*
         * x(:)=xstart;
         */
        mlfIndexAssign(&x, "(?)", mlfCreateColonIndex(), xstart);
        /*
         * if verbosity > 0
         */
        if (mlfTobool(mlfGt(verbosity, mlfScalar(0.0)))) {
            /*
             * disp(msg)
             */
            mlfDisp(msg);
        /*
         * end
         */
        }
        /*
         * return
         */
        goto return_;
    /*
     * end
     */
    }
    /*
     * lFinite = ~isinf(l);
     */
    mlfAssign(&lFinite, mlfNot(mlfIsinf(l)));
    /*
     * uFinite = ~isinf(u);
     */
    mlfAssign(&uFinite, mlfNot(mlfIsinf(u)));
    /*
     * 
     * if min(min(u-xstart),min(xstart-l)) < 0
     */
    if (mlfTobool(
          mlfLt(
            mlfMin(
              NULL,
              mlfMin(NULL, mlfMinus(u, xstart), NULL, NULL),
              mlfMin(NULL, mlfMinus(xstart, l), NULL, NULL),
              NULL),
            mlfScalar(0.0)))) {
        /*
         * xstart = startx(u,l); 
         */
        mlfAssign(&xstart, mlfOptim_private_startx(u, l));
    /*
     * end
     */
    }
    /*
     * 
     * diagnostics = isequal(optimget(options,'diagnostics','off'),'on');
     */
    mlfAssign(
      &diagnostics,
      mlfIsequal(
        mlfOptimget(
          options, mxCreateString("diagnostics"), mxCreateString("off")),
        mxCreateString("on"), NULL));
    /*
     * gradflag =  strcmp(optimget(options,'Jacobian'),'on');
     */
    mlfAssign(
      &gradflag,
      mlfStrcmp(
        mlfOptimget(options, mxCreateString("Jacobian"), NULL),
        mxCreateString("on")));
    /*
     * line_search = strcmp(optimget(options,'largescale','off'),'off'); % 0 means large-scale, 1 means line-search
     */
    mlfAssign(
      &line_search,
      mlfStrcmp(
        mlfOptimget(
          options, mxCreateString("largescale"), mxCreateString("off")),
        mxCreateString("off")));
    /*
     * 
     * % Convert to inline function as needed
     * if ~isempty(FUN)  % will detect empty string, empty matrix, empty cell array
     */
    if (mlfTobool(mlfNot(mlfIsempty(FUN)))) {
        /*
         * [funfcn, msg] = fprefcnchk(FUN,'lsqnonlin',length(varargin),gradflag);
         */
        mlfAssign(
          &funfcn,
          mlfLsqnonlin_fprefcnchk(
            &msg,
            FUN,
            mxCreateString("lsqnonlin"),
            mlfLength(varargin),
            gradflag));
    /*
     * else
     */
    } else {
        /*
         * errmsg = sprintf('%s\n%s', ...
         */
        mlfAssign(
          &errmsg,
          mlfSprintf(
            NULL,
            mxCreateString("%s\\n%s"),
            mxCreateString(
              "FUN must be a function name, valid st"
              "ring expression, or inline object;"),
            mxCreateString(
              " or, FUN may be a cell array that "
              "contains these type of objects."),
            NULL));
        /*
         * 'FUN must be a function name, valid string expression, or inline object;', ...
         * ' or, FUN may be a cell array that contains these type of objects.');
         * error(errmsg)
         */
        mlfError(errmsg);
    /*
     * end
     */
    }
    /*
     * 
     * x(:) = xstart;
     */
    mlfIndexAssign(&x, "(?)", mlfCreateColonIndex(), xstart);
    /*
     * switch funfcn{1}
     */
    {
        mxArray * t_ = mclUnassigned();
        mlfAssign(&t_, mlfIndexRef(funfcn, "{?}", mlfScalar(1.0)));
        /*
         * case 'fun'
         */
        if (mclSwitchCompare(t_, mxCreateString("fun"))) {
            /*
             * fuser = feval(funfcn{3},x,varargin{:});
             */
            mlfAssign(
              &fuser,
              mlfFeval(
                mclValueVarargout(),
                mclFevalLookup(
                  mlfIndexRef(funfcn, "{?}", mlfScalar(3.0)),
                  1,
                  local_function_table_),
                x,
                mlfIndexRef(varargin, "{?}", mlfCreateColonIndex()),
                NULL));
            /*
             * f = fuser(:);
             */
            mlfAssign(&f, mlfIndexRef(fuser, "(?)", mlfCreateColonIndex()));
            /*
             * nfun=length(f);
             */
            mlfAssign(&nfun, mlfLength(f));
            /*
             * JAC = zeros(nfun,numberOfVariables);
             */
            mlfAssign(&JAC, mlfZeros(nfun, numberOfVariables, NULL));
        /*
         * case 'fungrad'
         */
        } else if (mclSwitchCompare(t_, mxCreateString("fungrad"))) {
            /*
             * [fuser,JAC] = feval(funfcn{3},x,varargin{:});
             */
            mlfFeval(
              mlfVarargout(&fuser, &JAC, NULL),
              mclFevalLookup(
                mlfIndexRef(funfcn, "{?}", mlfScalar(3.0)),
                1,
                local_function_table_),
              x,
              mlfIndexRef(varargin, "{?}", mlfCreateColonIndex()),
              NULL);
            /*
             * f = fuser(:);
             */
            mlfAssign(&f, mlfIndexRef(fuser, "(?)", mlfCreateColonIndex()));
            /*
             * nfun=length(f);
             */
            mlfAssign(&nfun, mlfLength(f));
        /*
         * case 'fun_then_grad'
         */
        } else if (mclSwitchCompare(t_, mxCreateString("fun_then_grad"))) {
            /*
             * fuser = feval(funfcn{3},x,varargin{:}); 
             */
            mlfAssign(
              &fuser,
              mlfFeval(
                mclValueVarargout(),
                mclFevalLookup(
                  mlfIndexRef(funfcn, "{?}", mlfScalar(3.0)),
                  1,
                  local_function_table_),
                x,
                mlfIndexRef(varargin, "{?}", mlfCreateColonIndex()),
                NULL));
            /*
             * f = fuser(:);
             */
            mlfAssign(&f, mlfIndexRef(fuser, "(?)", mlfCreateColonIndex()));
            /*
             * JAC = feval(funfcn{4},x,varargin{:});
             */
            mlfAssign(
              &JAC,
              mlfFeval(
                mclValueVarargout(),
                mclFevalLookup(
                  mlfIndexRef(funfcn, "{?}", mlfScalar(4.0)),
                  1,
                  local_function_table_),
                x,
                mlfIndexRef(varargin, "{?}", mlfCreateColonIndex()),
                NULL));
            /*
             * nfun=length(f);
             */
            mlfAssign(&nfun, mlfLength(f));
        /*
         * otherwise
         */
        } else {
            /*
             * error('Undefined calltype in LSQNONLIN');
             */
            mlfError(mxCreateString("Undefined calltype in LSQNONLIN"));
        /*
         * end
         */
        }
        mxDestroyArray(t_);
    }
    /*
     * 
     * % check size of JAC
     * [Jrows, Jcols]=size(JAC);
     */
    mlfSize(mlfVarargout(&Jrows, &Jcols, NULL), JAC, NULL);
    /*
     * if Jrows~=nfun | Jcols ~=numberOfVariables
     */
    {
        mxArray * a_ = mclInitialize(mlfNe(Jrows, nfun));
        if (mlfTobool(a_)
            || mlfTobool(mlfOr(a_, mlfNe(Jcols, numberOfVariables)))) {
            mxDestroyArray(a_);
            /*
             * errstr = sprintf('%s\n%s%d%s%d\n',...
             */
            mlfAssign(
              &errstr,
              mlfSprintf(
                NULL,
                mxCreateString("%s\\n%s%d%s%d\\n"),
                mxCreateString(
                  "User-defined Jacobian is not the correct size:"),
                mxCreateString("    the Jacobian matrix should be "),
                nfun,
                mxCreateString("-by-"),
                numberOfVariables,
                NULL));
            /*
             * 'User-defined Jacobian is not the correct size:',...
             * '    the Jacobian matrix should be ',nfun,'-by-',numberOfVariables);
             * error(errstr);
             */
            mlfError(errstr);
        } else {
            mxDestroyArray(a_);
        }
    /*
     * end
     */
    }
    /*
     * 
     * YDATA = []; caller = 'lsqnonlin';
     */
    mlfAssign(&YDATA, mclCreateEmptyArray());
    mlfAssign(&caller, mxCreateString("lsqnonlin"));
    /*
     * 
     * % trustregion and enough equations (as many as variables) 
     * if ~line_search & nfun >= numberOfVariables 
     */
    {
        mxArray * a_ = mclInitialize(mlfNot(line_search));
        if (mlfTobool(a_)
            && mlfTobool(mlfAnd(a_, mlfGe(nfun, numberOfVariables)))) {
            mxDestroyArray(a_);
            /*
             * OUTPUT.algorithm = large;
             */
            mlfIndexAssign(OUTPUT, ".algorithm", large);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -