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

📄 ch2example16sfun.c

📁 清华大学出版社 邵玉斌编写的《通信系统建模与仿真实例分析》一书的所有MATLAB和SIMULINK代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (ts != NULL) {
        mclCopyOutputArg(ts, ts__);
    } else {
        mxDestroyArray(ts__);
    }
    return mlfReturnValue(sys);
}

/*
 * The function "mlxCh2example16sfun_mdlInitializeSizes" contains the feval
 * interface for the "ch2example16sfun/mdlInitializeSizes" M-function from file
 * "d:\syb\after20060609\清华大学出版社约稿\写作初稿\prog\ch2example16sfun.m"
 * (lines 25-40). The feval function calls the implementation version of
 * ch2example16sfun/mdlInitializeSizes through this function. This function
 * processes any input arguments and passes them to the implementation version
 * of the function, appearing above.
 */
static void mlxCh2example16sfun_mdlInitializeSizes(int nlhs,
                                                   mxArray * plhs[],
                                                   int nrhs,
                                                   mxArray * prhs[]) {
    mxArray * mprhs[4];
    mxArray * mplhs[4];
    int i;
    if (nlhs > 4) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: ch2example16sfun/mdlInitializeSizes Line: 2"
            "5 Column: 1 The function \"ch2example16sfun/mdlInitializeSizes\" "
            "was called with more than the declared number of outputs (4)."),
          NULL);
    }
    if (nrhs > 4) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: ch2example16sfun/mdlInitializeSizes Line: 2"
            "5 Column: 1 The function \"ch2example16sfun/mdlInitializeSizes\" "
            "was called with more than the declared number of inputs (4)."),
          NULL);
    }
    for (i = 0; i < 4; ++i) {
        mplhs[i] = NULL;
    }
    for (i = 0; i < 4 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 4; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(0, 4, mprhs[0], mprhs[1], mprhs[2], mprhs[3]);
    mplhs[0]
      = Mch2example16sfun_mdlInitializeSizes(
          &mplhs[1],
          &mplhs[2],
          &mplhs[3],
          nlhs,
          mprhs[0],
          mprhs[1],
          mprhs[2],
          mprhs[3]);
    mlfRestorePreviousContext(0, 4, mprhs[0], mprhs[1], mprhs[2], mprhs[3]);
    plhs[0] = mplhs[0];
    for (i = 1; i < 4 && i < nlhs; ++i) {
        plhs[i] = mplhs[i];
    }
    for (; i < 4; ++i) {
        mxDestroyArray(mplhs[i]);
    }
}

/*
 * The function "mlfCh2example16sfun_mdlDerivatives" contains the normal
 * interface for the "ch2example16sfun/mdlDerivatives" M-function from file
 * "d:\syb\after20060609\清华大学出版社约稿\写作初稿\prog\ch2example16sfun.m"
 * (lines 40-45). This function processes any input arguments and passes them
 * to the implementation version of the function, appearing above.
 */
static mxArray * mlfCh2example16sfun_mdlDerivatives(mxArray * t,
                                                    mxArray * x,
                                                    mxArray * u,
                                                    mxArray * A,
                                                    mxArray * B,
                                                    mxArray * C,
                                                    mxArray * D) {
    int nargout = 1;
    mxArray * sys = NULL;
    mlfEnterNewContext(0, 7, t, x, u, A, B, C, D);
    sys = Mch2example16sfun_mdlDerivatives(nargout, t, x, u, A, B, C, D);
    mlfRestorePreviousContext(0, 7, t, x, u, A, B, C, D);
    return mlfReturnValue(sys);
}

/*
 * The function "mlxCh2example16sfun_mdlDerivatives" contains the feval
 * interface for the "ch2example16sfun/mdlDerivatives" M-function from file
 * "d:\syb\after20060609\清华大学出版社约稿\写作初稿\prog\ch2example16sfun.m"
 * (lines 40-45). The feval function calls the implementation version of
 * ch2example16sfun/mdlDerivatives through this function. This function
 * processes any input arguments and passes them to the implementation version
 * of the function, appearing above.
 */
static void mlxCh2example16sfun_mdlDerivatives(int nlhs,
                                               mxArray * plhs[],
                                               int nrhs,
                                               mxArray * prhs[]) {
    mxArray * mprhs[7];
    mxArray * mplhs[1];
    int i;
    if (nlhs > 1) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: ch2example16sfun/mdlDerivatives Line: 40"
            " Column: 1 The function \"ch2example16sfun/mdlDerivatives\" wa"
            "s called with more than the declared number of outputs (1)."),
          NULL);
    }
    if (nrhs > 7) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: ch2example16sfun/mdlDerivatives Line: 40"
            " Column: 1 The function \"ch2example16sfun/mdlDerivatives\" wa"
            "s called with more than the declared number of inputs (7)."),
          NULL);
    }
    for (i = 0; i < 1; ++i) {
        mplhs[i] = NULL;
    }
    for (i = 0; i < 7 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 7; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(
      0,
      7,
      mprhs[0],
      mprhs[1],
      mprhs[2],
      mprhs[3],
      mprhs[4],
      mprhs[5],
      mprhs[6]);
    mplhs[0]
      = Mch2example16sfun_mdlDerivatives(
          nlhs,
          mprhs[0],
          mprhs[1],
          mprhs[2],
          mprhs[3],
          mprhs[4],
          mprhs[5],
          mprhs[6]);
    mlfRestorePreviousContext(
      0,
      7,
      mprhs[0],
      mprhs[1],
      mprhs[2],
      mprhs[3],
      mprhs[4],
      mprhs[5],
      mprhs[6]);
    plhs[0] = mplhs[0];
}

/*
 * The function "mlfCh2example16sfun_mdlOutputs" contains the normal interface
 * for the "ch2example16sfun/mdlOutputs" M-function from file
 * "d:\syb\after20060609\清华大学出版社约稿\写作初稿\prog\ch2example16sfun.m"
 * (lines 45-50). This function processes any input arguments and passes them
 * to the implementation version of the function, appearing above.
 */
static mxArray * mlfCh2example16sfun_mdlOutputs(mxArray * t,
                                                mxArray * x,
                                                mxArray * u,
                                                mxArray * A,
                                                mxArray * B,
                                                mxArray * C,
                                                mxArray * D) {
    int nargout = 1;
    mxArray * sys = NULL;
    mlfEnterNewContext(0, 7, t, x, u, A, B, C, D);
    sys = Mch2example16sfun_mdlOutputs(nargout, t, x, u, A, B, C, D);
    mlfRestorePreviousContext(0, 7, t, x, u, A, B, C, D);
    return mlfReturnValue(sys);
}

/*
 * The function "mlxCh2example16sfun_mdlOutputs" contains the feval interface
 * for the "ch2example16sfun/mdlOutputs" M-function from file
 * "d:\syb\after20060609\清华大学出版社约稿\写作初稿\prog\ch2example16sfun.m"
 * (lines 45-50). The feval function calls the implementation version of
 * ch2example16sfun/mdlOutputs through this function. This function processes
 * any input arguments and passes them to the implementation version of the
 * function, appearing above.
 */
static void mlxCh2example16sfun_mdlOutputs(int nlhs,
                                           mxArray * plhs[],
                                           int nrhs,
                                           mxArray * prhs[]) {
    mxArray * mprhs[7];
    mxArray * mplhs[1];
    int i;
    if (nlhs > 1) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: ch2example16sfun/mdlOutputs Line: 45 "
            "Column: 1 The function \"ch2example16sfun/mdlOutputs\" was "
            "called with more than the declared number of outputs (1)."),
          NULL);
    }
    if (nrhs > 7) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: ch2example16sfun/mdlOutputs Line: 45 "
            "Column: 1 The function \"ch2example16sfun/mdlOutputs\" was "
            "called with more than the declared number of inputs (7)."),
          NULL);
    }
    for (i = 0; i < 1; ++i) {
        mplhs[i] = NULL;
    }
    for (i = 0; i < 7 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 7; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(
      0,
      7,
      mprhs[0],
      mprhs[1],
      mprhs[2],
      mprhs[3],
      mprhs[4],
      mprhs[5],
      mprhs[6]);
    mplhs[0]
      = Mch2example16sfun_mdlOutputs(
          nlhs,
          mprhs[0],
          mprhs[1],
          mprhs[2],
          mprhs[3],
          mprhs[4],
          mprhs[5],
          mprhs[6]);
    mlfRestorePreviousContext(
      0,
      7,
      mprhs[0],
      mprhs[1],
      mprhs[2],
      mprhs[3],
      mprhs[4],
      mprhs[5],
      mprhs[6]);
    plhs[0] = mplhs[0];
}

/*
 * The function "Mch2example16sfun" is the implementation version of the
 * "ch2example16sfun" M-function from file
 * "d:\syb\after20060609\清华大学出版社约稿\写作初稿\prog\ch2example16sfun.m"
 * (lines 1-25). 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 [sys,x0,str,ts] =ch2example16Sfun(t,x,u,flag) 
 */
static mxArray * Mch2example16sfun(mxArray * * x0,
                                   mxArray * * str,
                                   mxArray * * ts,
                                   int nargout_,
                                   mxArray * t,
                                   mxArray * x,
                                   mxArray * u,
                                   mxArray * flag) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(
          &_local_function_table_ch2example16sfun);
    mxArray * sys = NULL;
    mxArray * ans = NULL;
    mxArray * D = NULL;
    mxArray * C = NULL;
    mxArray * B = NULL;
    mxArray * A = NULL;
    mclCopyArray(&t);
    mclCopyArray(&x);
    mclCopyArray(&u);
    mclCopyArray(&flag);
    /*
     * % 连续系统状态方程; 
     * % x'=Ax+Bu 
     * % y =Cx+Du 
     * % 定义A,B,C,D矩阵 
     * A=[0 1 0;0 0 1;-4 -6 -3]; 
     */
    mlfAssign(&A, _mxarray0_);
    /*
     * B=[0;0;1]; 
     */
    mlfAssign(&B, _mxarray2_);
    /*
     * C=[0 4 0]; 
     */

⌨️ 快捷键说明

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