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

📄 frac_tree_s.c

📁 科学运算语言 MATLAB 的程序设计有关的函数代码
💻 C
字号:
/*
 * MATLAB Compiler: 2.0
 * Date: Wed Apr 19 20:11:53 2000
 * Arguments: "-m" "frac_tree_s.m" 
 */
#include "frac_tree_s.h"

/*
 * The function "Mfrac_tree_s" is the implementation version of the
 * "frac_tree_s" M-function from file
 * "C:\Xue.Dy\BOOKS\MATLAB\mat5progs\mat5files\frac_tree_s.m" (lines 1-15). 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 [x,y]=frac_tree_s()
 */
static mxArray * Mfrac_tree_s(mxArray * * y, int nargout_) {
    mxArray * x = mclGetUninitializedArray();
    mxArray * N = mclGetUninitializedArray();
    mxArray * i = mclGetUninitializedArray();
    mclForLoopIterator iterator_0;
    mxArray * v = mclGetUninitializedArray();
    mxArray * vv = mclGetUninitializedArray();
    mxArray * x0 = mclGetUninitializedArray();
    mxArray * y0 = mclGetUninitializedArray();
    /*
     * x0=0; y0=0; N=1000000; v=rand(N,1);
     */
    mlfAssign(&x0, mlfScalar(0.0));
    mlfAssign(&y0, mlfScalar(0.0));
    mlfAssign(&N, mlfScalar(1000000.0));
    mlfAssign(&v, mlfRand(N, mlfScalar(1.0), NULL));
    /*
     * x=[x0; zeros(N-1,1)]; y=[y0; zeros(N-1,1)];
     */
    mlfAssign(
      &x,
      mlfVertcat(
        mlfHorzcat(x0, NULL),
        mlfHorzcat(
          mlfZeros(mlfMinus(N, mlfScalar(1.0)), mlfScalar(1.0), NULL), NULL),
        NULL));
    mlfAssign(
      y,
      mlfVertcat(
        mlfHorzcat(y0, NULL),
        mlfHorzcat(
          mlfZeros(mlfMinus(N, mlfScalar(1.0)), mlfScalar(1.0), NULL), NULL),
        NULL));
    /*
     * for i=2:N
     */
    for (mclForStart(&iterator_0, mlfScalar(2.0), N, NULL);
         mclForNext(&iterator_0, &i);
         ) {
        /*
         * vv=v(i);
         */
        mlfAssign(&vv, mlfIndexRef(v, "(?)", i));
        /*
         * if vv<0.05, y(i)=0.5*y(i-1);   
         */
        if (mlfTobool(mlfLt(vv, mlfScalar(0.05)))) {
            mlfIndexAssign(
              y,
              "(?)",
              i,
              mlfMtimes(
                mlfScalar(0.5),
                mlfIndexRef(*y, "(?)", mlfMinus(i, mlfScalar(1.0)))));
        /*
         * elseif vv<0.45, 
         */
        } else if (mlfTobool(mlfLt(vv, mlfScalar(0.45)))) {
            /*
             * x(i)=0.42*(x(i-1)-y(i-1)); y(i)=0.2+0.42*(x(i-1)+y(i-1));
             */
            mlfIndexAssign(
              &x,
              "(?)",
              i,
              mlfMtimes(
                mlfScalar(0.42),
                mlfMinus(
                  mlfIndexRef(x, "(?)", mlfMinus(i, mlfScalar(1.0))),
                  mlfIndexRef(*y, "(?)", mlfMinus(i, mlfScalar(1.0))))));
            mlfIndexAssign(
              y,
              "(?)",
              i,
              mlfPlus(
                mlfScalar(0.2),
                mlfMtimes(
                  mlfScalar(0.42),
                  mlfPlus(
                    mlfIndexRef(x, "(?)", mlfMinus(i, mlfScalar(1.0))),
                    mlfIndexRef(*y, "(?)", mlfMinus(i, mlfScalar(1.0)))))));
        /*
         * elseif vv<0.85, 
         */
        } else if (mlfTobool(mlfLt(vv, mlfScalar(0.85)))) {
            /*
             * x(i)=0.42*(x(i-1)+y(i-1)); y(i)=0.2-0.42*(x(i-1)-y(i-1));   
             */
            mlfIndexAssign(
              &x,
              "(?)",
              i,
              mlfMtimes(
                mlfScalar(0.42),
                mlfPlus(
                  mlfIndexRef(x, "(?)", mlfMinus(i, mlfScalar(1.0))),
                  mlfIndexRef(*y, "(?)", mlfMinus(i, mlfScalar(1.0))))));
            mlfIndexAssign(
              y,
              "(?)",
              i,
              mlfMinus(
                mlfScalar(0.2),
                mlfMtimes(
                  mlfScalar(0.42),
                  mlfMinus(
                    mlfIndexRef(x, "(?)", mlfMinus(i, mlfScalar(1.0))),
                    mlfIndexRef(*y, "(?)", mlfMinus(i, mlfScalar(1.0)))))));
        /*
         * else, 
         */
        } else {
            /*
             * x(i)=0.1*x(i-1); y(i)=0.1*y(i-1)+0.2;
             */
            mlfIndexAssign(
              &x,
              "(?)",
              i,
              mlfMtimes(
                mlfScalar(0.1),
                mlfIndexRef(x, "(?)", mlfMinus(i, mlfScalar(1.0)))));
            mlfIndexAssign(
              y,
              "(?)",
              i,
              mlfPlus(
                mlfMtimes(
                  mlfScalar(0.1),
                  mlfIndexRef(*y, "(?)", mlfMinus(i, mlfScalar(1.0)))),
                mlfScalar(0.2)));
        /*
         * end
         */
        }
    /*
     * end
     */
    }
    mclValidateOutputs("frac_tree_s", 2, nargout_, &x, y);
    mxDestroyArray(N);
    mxDestroyArray(i);
    mxDestroyArray(v);
    mxDestroyArray(vv);
    mxDestroyArray(x0);
    mxDestroyArray(y0);
    return x;
}

/*
 * The function "mlfFrac_tree_s" contains the normal interface for the
 * "frac_tree_s" M-function from file
 * "C:\Xue.Dy\BOOKS\MATLAB\mat5progs\mat5files\frac_tree_s.m" (lines 1-15).
 * This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
mxArray * mlfFrac_tree_s(mxArray * * y) {
    int nargout = 1;
    mxArray * x = mclGetUninitializedArray();
    mxArray * y__ = mclGetUninitializedArray();
    mlfEnterNewContext(1, 0, y);
    if (y != NULL) {
        ++nargout;
    }
    x = Mfrac_tree_s(&y__, nargout);
    mlfRestorePreviousContext(1, 0, y);
    if (y != NULL) {
        mclCopyOutputArg(y, y__);
    } else {
        mxDestroyArray(y__);
    }
    return mlfReturnValue(x);
}

/*
 * The function "mlxFrac_tree_s" contains the feval interface for the
 * "frac_tree_s" M-function from file
 * "C:\Xue.Dy\BOOKS\MATLAB\mat5progs\mat5files\frac_tree_s.m" (lines 1-15). The
 * feval function calls the implementation version of frac_tree_s through this
 * function. This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
void mlxFrac_tree_s(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    mxArray * mplhs[2];
    int i;
    if (nlhs > 2) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: frac_tree_s Line: 1 Column"
            ": 0 The function \"frac_tree_s\" was called with"
            " more than the declared number of outputs (2)"));
    }
    if (nrhs > 0) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: frac_tree_s Line: 1 Column"
            ": 0 The function \"frac_tree_s\" was called with"
            " more than the declared number of inputs (0)"));
    }
    for (i = 0; i < 2; ++i) {
        mplhs[i] = NULL;
    }
    mlfEnterNewContext(0, 0);
    mplhs[0] = Mfrac_tree_s(&mplhs[1], nlhs);
    mlfRestorePreviousContext(0, 0);
    plhs[0] = mplhs[0];
    for (i = 1; i < 2 && i < nlhs; ++i) {
        plhs[i] = mplhs[i];
    }
    for (; i < 2; ++i) {
        mxDestroyArray(mplhs[i]);
    }
}

⌨️ 快捷键说明

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