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

📄 cubici2.c

📁 ASUFIT-Matlab-全局拟合程序
💻 C
字号:
/*
 * MATLAB Compiler: 2.0.1
 * Date: Tue May 08 21:28:23 2001
 * Arguments: "-B" "sgl" "-m" "-W" "mainhg" "-L" "C" "asufit.m" "absfun.m"
 * "absfunfree.m" "absfunshift.m" "absfunwidth.m" "dispfit.m" "dispfitdisp.m"
 * "dispfitfree.m" "dispfitwidth.m" "seqmodfree.m" "spcfun.m" "spcfun1.m"
 * "atamult.m" "aprecon.m" 
 */
#include "cubici2.h"
#include "quadi.h"

/*
 * The function "Mcubici2" is the implementation version of the "cubici2"
 * M-function from file "C:\MATLABR11\toolbox\optim\cubici2.m" (lines 1-22). It
 * contains the actual compiled code for that M-function. It is a static
 * function and must only be called from one of the interface functions,
 * appearing below.
 */
/*
 * function [stepmin]=cubici2(graddold,matl,matx)
 */
static mxArray * Mcubici2(int nargout_,
                          mxArray * graddold,
                          mxArray * matl,
                          mxArray * matx) {
    mxArray * stepmin = mclGetUninitializedArray();
    mxArray * abd = mclGetUninitializedArray();
    mxArray * root = mclGetUninitializedArray();
    mxArray * x1 = mclGetUninitializedArray();
    mclValidateInputs("cubici2", 3, &graddold, &matl, &matx);
    /*
     * %CUBICI2 Cubicly interpolates 3 points and 1 gradient.
     * %
     * %   This function uses cubic interpolation and
     * %   the values of 3  points and one gradient.
     * 
     * %   Copyright (c) 1990-98 by The MathWorks, Inc.
     * %   $Revision: 1.9 $  $Date: 1997/11/29 01:23:02 $
     * %   Andy Grace 7-9-90.
     * abd=[1/3*matx.^3, 0.5*matx.^2, ones(3,1)]\(matl-graddold*matx);
     */
    mlfAssign(
      &abd,
      mlfMldivide(
        mlfHorzcat(
          mlfMtimes(
            mlfMrdivide(mlfScalar(1.0), mlfScalar(3.0)),
            mlfPower(matx, mlfScalar(3.0))),
          mlfMtimes(mlfScalar(0.5), mlfPower(matx, mlfScalar(2.0))),
          mlfOnes(mlfScalar(3.0), mlfScalar(1.0), NULL),
          NULL),
        mlfMinus(matl, mlfMtimes(graddold, matx))));
    /*
     * root=real(sqrt(abd(2)^2-4*abd(1)*graddold));
     */
    mlfAssign(
      &root,
      mlfReal(
        mlfSqrt(
          mlfMinus(
            mlfMpower(mlfIndexRef(abd, "(?)", mlfScalar(2.0)), mlfScalar(2.0)),
            mlfMtimes(
              mlfMtimes(
                mlfScalar(4.0), mlfIndexRef(abd, "(?)", mlfScalar(1.0))),
              graddold)))));
    /*
     * x1=(-abd(2)+root)/(2*abd(1));
     */
    mlfAssign(
      &x1,
      mlfMrdivide(
        mlfPlus(mlfUminus(mlfIndexRef(abd, "(?)", mlfScalar(2.0))), root),
        mlfMtimes(mlfScalar(2.0), mlfIndexRef(abd, "(?)", mlfScalar(1.0)))));
    /*
     * if 2*abd(1)*x1+abd(2)>0
     */
    if (mlfTobool(
          mlfGt(
            mlfPlus(
              mlfMtimes(
                mlfMtimes(
                  mlfScalar(2.0), mlfIndexRef(abd, "(?)", mlfScalar(1.0))),
                x1),
              mlfIndexRef(abd, "(?)", mlfScalar(2.0))),
            mlfScalar(0.0)))) {
        /*
         * stepmin=x1;
         */
        mlfAssign(&stepmin, x1);
    /*
     * else
     */
    } else {
        /*
         * stepmin=(-abd(2)-root)/(2*abd(1));
         */
        mlfAssign(
          &stepmin,
          mlfMrdivide(
            mlfMinus(mlfUminus(mlfIndexRef(abd, "(?)", mlfScalar(2.0))), root),
            mlfMtimes(
              mlfScalar(2.0), mlfIndexRef(abd, "(?)", mlfScalar(1.0)))));
    /*
     * end
     */
    }
    /*
     * if stepmin<0|isnan(stepmin)| isinf(stepmin), stepmin=abs(quadi(matx,matl));end
     */
    {
        mxArray * a_ = mclInitialize(mlfLt(stepmin, mlfScalar(0.0)));
        if (mlfTobool(a_)) {
            mlfAssign(&a_, mlfScalar(1));
        } else {
            mlfAssign(&a_, mlfOr(a_, mlfIsnan(stepmin)));
        }
        if (mlfTobool(a_) || mlfTobool(mlfOr(a_, mlfIsinf(stepmin)))) {
            mxDestroyArray(a_);
            mlfAssign(&stepmin, mlfAbs(mlfQuadi(matx, matl)));
        } else {
            mxDestroyArray(a_);
        }
    }
    /*
     * if isnan(stepmin),stepmin=matx(2)/2; end
     */
    if (mlfTobool(mlfIsnan(stepmin))) {
        mlfAssign(
          &stepmin,
          mlfMrdivide(
            mlfIndexRef(matx, "(?)", mlfScalar(2.0)), mlfScalar(2.0)));
    }
    mclValidateOutputs("cubici2", 1, nargout_, &stepmin);
    mxDestroyArray(abd);
    mxDestroyArray(root);
    mxDestroyArray(x1);
    /*
     * 
     * % fbest=1/3*abd(1)*stepmin^3+0.5*abd(2)*stepmin^2+graddold*stepmin+matl(1);
     */
    return stepmin;
}

/*
 * The function "mlfCubici2" contains the normal interface for the "cubici2"
 * M-function from file "C:\MATLABR11\toolbox\optim\cubici2.m" (lines 1-22).
 * This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
mxArray * mlfCubici2(mxArray * graddold, mxArray * matl, mxArray * matx) {
    int nargout = 1;
    mxArray * stepmin = mclGetUninitializedArray();
    mlfEnterNewContext(0, 3, graddold, matl, matx);
    stepmin = Mcubici2(nargout, graddold, matl, matx);
    mlfRestorePreviousContext(0, 3, graddold, matl, matx);
    return mlfReturnValue(stepmin);
}

/*
 * The function "mlxCubici2" contains the feval interface for the "cubici2"
 * M-function from file "C:\MATLABR11\toolbox\optim\cubici2.m" (lines 1-22).
 * The feval function calls the implementation version of cubici2 through this
 * function. This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
void mlxCubici2(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    mxArray * mprhs[3];
    mxArray * mplhs[1];
    int i;
    if (nlhs > 1) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: cubici2 Line: 1 Column: "
            "0 The function \"cubici2\" was called with mor"
            "e than the declared number of outputs (1)"));
    }
    if (nrhs > 3) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: cubici2 Line: 1 Column:"
            " 0 The function \"cubici2\" was called with m"
            "ore than the declared number of inputs (3)"));
    }
    for (i = 0; i < 1; ++i) {
        mplhs[i] = NULL;
    }
    for (i = 0; i < 3 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 3; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(0, 3, mprhs[0], mprhs[1], mprhs[2]);
    mplhs[0] = Mcubici2(nlhs, mprhs[0], mprhs[1], mprhs[2]);
    mlfRestorePreviousContext(0, 3, mprhs[0], mprhs[1], mprhs[2]);
    plhs[0] = mplhs[0];
}

⌨️ 快捷键说明

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