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

📄 my_yprime_m.c

📁 该程序为MATLAB对CDMA系统个部分的仿真
💻 C
字号:
/*
 * MATLAB Compiler: 2.2
 * Date: Tue Jun 25 10:37:38 2002
 * Arguments: "-B" "macro_default" "-O" "all" "-O" "fold_scalar_mxarrays:on"
 * "-O" "fold_non_scalar_mxarrays:on" "-O" "optimize_integer_for_loops:on" "-O"
 * "array_indexing:on" "-O" "optimize_conditionals:on" "-x" "-W" "mex" "-L" "C"
 * "-t" "-T" "link:mexlibrary" "libmatlbmx.mlib" "my_yprime_m" 
 */
#include "my_yprime_m.h"
#include "libmatlbm.h"

static mxChar _array1_[140] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
                                'l', 'e', ':', ' ', 'm', 'y', '_', 'y', 'p',
                                'r', 'i', 'm', 'e', '_', 'm', ' ', 'L', 'i',
                                'n', 'e', ':', ' ', '1', ' ', 'C', 'o', 'l',
                                'u', 'm', 'n', ':', ' ', '1', ' ', 'T', 'h',
                                'e', ' ', 'f', 'u', 'n', 'c', 't', 'i', 'o',
                                'n', ' ', '"', 'm', 'y', '_', 'y', 'p', 'r',
                                'i', 'm', 'e', '_', 'm', '"', ' ', 'w', 'a',
                                's', ' ', 'c', 'a', 'l', 'l', 'e', 'd', ' ',
                                'w', 'i', 't', 'h', ' ', 'm', 'o', 'r', 'e',
                                ' ', 't', 'h', 'a', 'n', ' ', 't', 'h', 'e',
                                ' ', 'd', 'e', 'c', 'l', 'a', 'r', 'e', 'd',
                                ' ', 'n', 'u', 'm', 'b', 'e', 'r', ' ', 'o',
                                'f', ' ', 'o', 'u', 't', 'p', 'u', 't', 's',
                                ' ', '(', '1', ')', '.' };
static mxArray * _mxarray0_;

static mxChar _array3_[139] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
                                'l', 'e', ':', ' ', 'm', 'y', '_', 'y', 'p',
                                'r', 'i', 'm', 'e', '_', 'm', ' ', 'L', 'i',
                                'n', 'e', ':', ' ', '1', ' ', 'C', 'o', 'l',
                                'u', 'm', 'n', ':', ' ', '1', ' ', 'T', 'h',
                                'e', ' ', 'f', 'u', 'n', 'c', 't', 'i', 'o',
                                'n', ' ', '"', 'm', 'y', '_', 'y', 'p', 'r',
                                'i', 'm', 'e', '_', 'm', '"', ' ', 'w', 'a',
                                's', ' ', 'c', 'a', 'l', 'l', 'e', 'd', ' ',
                                'w', 'i', 't', 'h', ' ', 'm', 'o', 'r', 'e',
                                ' ', 't', 'h', 'a', 'n', ' ', 't', 'h', 'e',
                                ' ', 'd', 'e', 'c', 'l', 'a', 'r', 'e', 'd',
                                ' ', 'n', 'u', 'm', 'b', 'e', 'r', ' ', 'o',
                                'f', ' ', 'i', 'n', 'p', 'u', 't', 's', ' ',
                                '(', '2', ')', '.' };
static mxArray * _mxarray2_;
static mxArray * _mxarray4_;
static mxArray * _mxarray5_;
static mxArray * _mxarray6_;
static mxArray * _mxarray7_;
static mxArray * _mxarray8_;

void InitializeModule_my_yprime_m(void) {
    _mxarray0_ = mclInitializeString(140, _array1_);
    _mxarray2_ = mclInitializeString(139, _array3_);
    _mxarray4_ = mclInitializeDouble(.01212856276531231);
    _mxarray5_ = mclInitializeDouble(1.0);
    _mxarray6_ = mclInitializeDouble(2.0);
    _mxarray7_ = mclInitializeDouble(3.0);
    _mxarray8_ = mclInitializeDouble(-2.0);
}

void TerminateModule_my_yprime_m(void) {
    mxDestroyArray(_mxarray8_);
    mxDestroyArray(_mxarray7_);
    mxDestroyArray(_mxarray6_);
    mxDestroyArray(_mxarray5_);
    mxDestroyArray(_mxarray4_);
    mxDestroyArray(_mxarray2_);
    mxDestroyArray(_mxarray0_);
}

static mxArray * Mmy_yprime_m(int nargout_, mxArray * t, mxArray * y);

_mexLocalFunctionTable _local_function_table_my_yprime_m
  = { 0, (mexFunctionTableEntry *)NULL };

/*
 * The function "mlfMy_yprime_m" contains the normal interface for the
 * "my_yprime_m" M-function from file "D:\mywork\my_yprime_m.m" (lines 1-25).
 * This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
mxArray * mlfMy_yprime_m(mxArray * t, mxArray * y) {
    int nargout = 1;
    mxArray * yp = mclGetUninitializedArray();
    mlfEnterNewContext(0, 2, t, y);
    yp = Mmy_yprime_m(nargout, t, y);
    mlfRestorePreviousContext(0, 2, t, y);
    return mlfReturnValue(yp);
}

/*
 * The function "mlxMy_yprime_m" contains the feval interface for the
 * "my_yprime_m" M-function from file "D:\mywork\my_yprime_m.m" (lines 1-25).
 * The feval function calls the implementation version of my_yprime_m through
 * this function. This function processes any input arguments and passes them
 * to the implementation version of the function, appearing above.
 */
void mlxMy_yprime_m(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    mxArray * mprhs[2];
    mxArray * mplhs[1];
    int i;
    if (nlhs > 1) {
        mlfError(_mxarray0_);
    }
    if (nrhs > 2) {
        mlfError(_mxarray2_);
    }
    for (i = 0; i < 1; ++i) {
        mplhs[i] = mclGetUninitializedArray();
    }
    for (i = 0; i < 2 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 2; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(0, 2, mprhs[0], mprhs[1]);
    mplhs[0] = Mmy_yprime_m(nlhs, mprhs[0], mprhs[1]);
    mlfRestorePreviousContext(0, 2, mprhs[0], mprhs[1]);
    plhs[0] = mplhs[0];
}

/*
 * The function "Mmy_yprime_m" is the implementation version of the
 * "my_yprime_m" M-function from file "D:\mywork\my_yprime_m.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 yp = yprime(t,y)
 */
static mxArray * Mmy_yprime_m(int nargout_, mxArray * t, mxArray * y) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_my_yprime_m);
    mxArray * yp = mclGetUninitializedArray();
    mxArray * r2 = mclGetUninitializedArray();
    mxArray * r1 = mclGetUninitializedArray();
    mxArray * mus = mclGetUninitializedArray();
    mxArray * mu = mclGetUninitializedArray();
    mclCopyArray(&t);
    mclCopyArray(&y);
    /*
     * % Differential equation system for restricted three body problem.
     * % Think of a small third body in orbit about the earth and moon.
     * % The coordinate system moves with the earth-moon system.
     * % The 1-axis goes through the earth and the moon.
     * % The 2-axis is perpendicular, in the plane of motion of the third body.
     * % The origin is at the center of gravity of the two heavy bodies.
     * % Let mu = the ratio of the mass of the moon to the mass of the earth.
     * % The earth is located at (-mu,0) and the moon at (1-mu,0). 
     * % y(1) and y(3) = coordinates of the third body.
     * % y(2) and y(4) = velocity of the third body
     * %.
     * % Copyright (c) 1984-98 by The MathWorks, Inc.
     * % All Rights Reserved.
     * 
     * mu = 1/82.45;
     */
    mlfAssign(&mu, _mxarray4_);
    /*
     * mus = 1-mu;
     */
    mlfAssign(&mus, mclMinus(_mxarray5_, mclVv(mu, "mu")));
    /*
     * r1 = norm([y(1)+mu, y(3)]);   % Distance to the earth
     */
    mlfAssign(
      &r1,
      mlfNorm(
        mlfHorzcat(
          mclPlus(mclVe(mclIntArrayRef1(mclVsa(y, "y"), 1)), mclVv(mu, "mu")),
          mclVe(mclIntArrayRef1(mclVsa(y, "y"), 3)),
          NULL),
        NULL));
    /*
     * r2 = norm([y(1)-mus, y(3)]);  % Distance to the moon
     */
    mlfAssign(
      &r2,
      mlfNorm(
        mlfHorzcat(
          mclMinus(
            mclVe(mclIntArrayRef1(mclVsa(y, "y"), 1)), mclVv(mus, "mus")),
          mclVe(mclIntArrayRef1(mclVsa(y, "y"), 3)),
          NULL),
        NULL));
    /*
     * yp(1) = y(2);
     */
    mclIntArrayAssign1(&yp, mclIntArrayRef1(mclVsa(y, "y"), 2), 1);
    /*
     * yp(2) = 2*y(4) + y(1) - mus*(y(1)+mu)/r1^3 - mu*(y(1)-mus)/r2^3;
     */
    mclIntArrayAssign1(
      &yp,
      mclMinus(
        mclMinus(
          mclPlus(
            mclMtimes(_mxarray6_, mclVe(mclIntArrayRef1(mclVsa(y, "y"), 4))),
            mclVe(mclIntArrayRef1(mclVsa(y, "y"), 1))),
          mclMrdivide(
            mclMtimes(
              mclVv(mus, "mus"),
              mclPlus(
                mclVe(mclIntArrayRef1(mclVsa(y, "y"), 1)), mclVv(mu, "mu"))),
            mclMpower(mclVv(r1, "r1"), _mxarray7_))),
        mclMrdivide(
          mclMtimes(
            mclVv(mu, "mu"),
            mclMinus(
              mclVe(mclIntArrayRef1(mclVsa(y, "y"), 1)), mclVv(mus, "mus"))),
          mclMpower(mclVv(r2, "r2"), _mxarray7_))),
      2);
    /*
     * yp(3) = y(4);
     */
    mclIntArrayAssign1(&yp, mclIntArrayRef1(mclVsa(y, "y"), 4), 3);
    /*
     * yp(4) = -2*y(2) + y(3) - mus*y(3)/r1^3 - mu*y(3)/r2^3;
     */
    mclIntArrayAssign1(
      &yp,
      mclMinus(
        mclMinus(
          mclPlus(
            mclMtimes(_mxarray8_, mclVe(mclIntArrayRef1(mclVsa(y, "y"), 2))),
            mclVe(mclIntArrayRef1(mclVsa(y, "y"), 3))),
          mclMrdivide(
            mclMtimes(
              mclVv(mus, "mus"), mclVe(mclIntArrayRef1(mclVsa(y, "y"), 3))),
            mclMpower(mclVv(r1, "r1"), _mxarray7_))),
        mclMrdivide(
          mclMtimes(mclVv(mu, "mu"), mclVe(mclIntArrayRef1(mclVsa(y, "y"), 3))),
          mclMpower(mclVv(r2, "r2"), _mxarray7_))),
      4);
    /*
     * yp = yp';
     */
    mlfAssign(&yp, mlfCtranspose(mclVv(yp, "yp")));
    mclValidateOutput(yp, 1, nargout_, "yp", "my_yprime_m");
    mxDestroyArray(mu);
    mxDestroyArray(mus);
    mxDestroyArray(r1);
    mxDestroyArray(r2);
    mxDestroyArray(y);
    mxDestroyArray(t);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return yp;
}

⌨️ 快捷键说明

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