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

📄 xode.cpp

📁 实用化工计算机模拟-Matlab在化学工程中的应用源代码
💻 CPP
字号:
//
// MATLAB Compiler: 3.0
// Date: Mon Jul 02 23:48:58 2007
// 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" "-M" "-silentsetup" "-d"
// "F:/转移/matlab/实用化工计算机模拟-Matlab在化学工程中的应用/Examples/Chapter
// 3/123/src" "-v" "-B" "cppsglcom:123,123,1.0" "-B" "csglcom:123,123,1.0" "-B"
// "sgl" "-m" "-W" "main" "-L" "C" "-t" "-T" "link:exe" "-h" "libmmfile.mlib"
// "-W" "mainhg" "libmwsglm.mlib" "-t" "-W" "comhg:123,123,1.0" "-T" "link:lib"
// "-h" "libmmfile.mlib" "-i" "-L" "cpp" "-g" "-G" "-A" "debugline:on" "-O"
// "none" "-O" "fold_scalar_mxarrays:off" "-O" "fold_non_scalar_mxarrays:off"
// "-O" "optimize_integer_for_loops:off" "-O" "array_indexing:off" "-O"
// "optimize_conditionals:off" "-O" "speculate:off" "-i"
// "D:/MATLAB6p5/work/xODE.m" 
//
#include "xode.hpp"
#include "libmatlbm.hpp"
#include "libmmfile.hpp"
#include "xlabel.hpp"
#include "ylabel.hpp"

static double _array0_[2] = { 0.0, 1.0 };

void InitializeModule_xode() {
}

void TerminateModule_xode() {
}

static mwArray xode_f(mwArray x = mwArray::DIN, mwArray y = mwArray::DIN);
#ifdef __cplusplus
extern "C"
#endif
void mlxXode_f(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]);
static void Mxode();
static mwArray Mxode_f(int nargout_, mwArray x, mwArray y);

static mexFunctionTableEntry local_function_table_[1]
  = { { "f", mlxXode_f, 2, 1, NULL } };

_mexLocalFunctionTable _local_function_table_xode
  = { 1, local_function_table_ };

//
// The function "xode" contains the normal interface for the "xode" M-function
// from file "d:\matlab6p5\work\xode.m" (lines 1-23). This function processes
// any input arguments and passes them to the implementation version of the
// function, appearing above.
//
void xode() {
    Mxode();
}

//
// The function "mlxXode" contains the feval interface for the "xode"
// M-function from file "d:\matlab6p5\work\xode.m" (lines 1-23). The feval
// function calls the implementation version of xode through this function.
// This function processes any input arguments and passes them to the
// implementation version of the function, appearing above.
//
void mlxXode(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    MW_BEGIN_MLX();
    {
        if (nlhs > 0) {
            error(
              mwVarargin(
                mwArray(
                  "Run-time Error: File: xode Line: 1 Column: 1"
                  " The function \"xode\" was called with more "
                  "than the declared number of outputs (0).")));
        }
        if (nrhs > 0) {
            error(
              mwVarargin(
                mwArray(
                  "Run-time Error: File: xode Line: 1 Column: 1"
                  " The function \"xode\" was called with more "
                  "than the declared number of inputs (0).")));
        }
        Mxode();
    }
    MW_END_MLX();
}

//
// The function "xode_f" contains the normal interface for the "xode/f"
// M-function from file "d:\matlab6p5\work\xode.m" (lines 23-24). This function
// processes any input arguments and passes them to the implementation version
// of the function, appearing above.
//
static mwArray xode_f(mwArray x, mwArray y) {
    int nargout = 1;
    mwArray dydx = mwArray::UNDEFINED;
    dydx = Mxode_f(nargout, x, y);
    return dydx;
}

//
// The function "mlxXode_f" contains the feval interface for the "xode/f"
// M-function from file "d:\matlab6p5\work\xode.m" (lines 23-24). The feval
// function calls the implementation version of xode/f through this function.
// This function processes any input arguments and passes them to the
// implementation version of the function, appearing above.
//
void mlxXode_f(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    MW_BEGIN_MLX();
    {
        mwArray mprhs[2];
        mwArray mplhs[1];
        int i;
        mclCppUndefineArrays(1, mplhs);
        if (nlhs > 1) {
            error(
              mwVarargin(
                mwArray(
                  "Run-time Error: File: xode/f Line: 23 Column: "
                  "1 The function \"xode/f\" was called with more"
                  " than the declared number of outputs (1).")));
        }
        if (nrhs > 2) {
            error(
              mwVarargin(
                mwArray(
                  "Run-time Error: File: xode/f Line: 23 Column: "
                  "1 The function \"xode/f\" was called with more"
                  " than the declared number of inputs (2).")));
        }
        for (i = 0; i < 2 && i < nrhs; ++i) {
            mprhs[i] = mwArray(prhs[i], 0);
        }
        for (; i < 2; ++i) {
            mprhs[i].MakeDIN();
        }
        mplhs[0] = Mxode_f(nlhs, mprhs[0], mprhs[1]);
        plhs[0] = mplhs[0].FreezeData();
    }
    MW_END_MLX();
}

//
// The function "Mxode" is the implementation version of the "xode" M-function
// from file "d:\matlab6p5\work\xode.m" (lines 1-23). 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 xODE
//
static void Mxode() {
    mclMlineEnterFunction("d:\\matlab6p5\\work\\xode.m", "xode")
    mwLocalFunctionTable save_local_function_table_
      = &_local_function_table_xode;
    mwArray y2 = mwArray::UNDEFINED;
    mwArray x2 = mwArray::UNDEFINED;
    mwArray y1 = mwArray::UNDEFINED;
    mwArray x1 = mwArray::UNDEFINED;
    mwArray y0 = mwArray::UNDEFINED;
    mwArray ans = mwArray::UNDEFINED;
    //
    // % xODE.m
    // % Demonstrate how to use ode45() and ode23()
    // %
    // %   Author: HUANG Huajiang
    // %   Copyright 2003 UNILAB Research Center, 
    // %   East China University of Science and Technology, Shanghai, PRC
    // %   $Revision: 1.0 $  $Date: 2003/02/24 $
    // 
    // clear all
    //
    mclMline(10);
    clear(&ans, &x1, &x2, &y0, &y1, &y2, NULL);
    //
    // clc
    //
    mclMline(11);
    clc();
    //
    // 
    // format long
    //
    mclMline(13);
    format(mwArray("long"));
    //
    // 
    // y0 = 1;
    //
    mclMline(15);
    y0 = 1;
    //
    // [x1,y1] = ode45(@f,[0,1],y0)
    //
    mclMline(16);
    Node45(
      0,
      mwVarargout(x1, y1),
      mwArray(mlxXode_f, "f"),
      mwArray(1, 2, _array0_, (double *)NULL),
      mwVv(y0, "y0"));
    mwVv(x1, "x1").Print("x1");
    mwVv(y1, "y1").Print("y1");
    //
    // [x2,y2] = ode23(@f,[0,1],y0)
    //
    mclMline(17);
    Node23(
      0,
      mwVarargout(x2, y2),
      mwArray(mlxXode_f, "f"),
      mwArray(1, 2, _array0_, (double *)NULL),
      mwVv(y0, "y0"));
    mwVv(x2, "x2").Print("x2");
    mwVv(y2, "y2").Print("y2");
    //
    // plot(x1,y1,'k-',x2,y2,'b--')
    //
    mclMline(18);
    ans.EqPrintAns(
      Nplot(
        0,
        mwVarargin(
          mwVv(x1, "x1"),
          mwVv(y1, "y1"),
          "k-",
          mwVv(x2, "x2"),
          mwVv(y2, "y2"),
          "b--")));
    //
    // xlabel('x')
    //
    mclMline(19);
    ans.EqPrintAns(Nxlabel(0, mwArray("x"), mwVarargin()));
    //
    // ylabel('y')
    //
    mclMline(20);
    ans.EqPrintAns(Nylabel(0, mwArray("y"), mwVarargin()));
    //
    // 
    // % ------------------------------------------------------------------
    //
    mclMline(22);
    mclMlineExitFunction();
}

//
// The function "Mxode_f" is the implementation version of the "xode/f"
// M-function from file "d:\matlab6p5\work\xode.m" (lines 23-24). 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 dydx = f(x,y)
//
static mwArray Mxode_f(int nargout_, mwArray x, mwArray y) {
    mclMlineEnterFunction("d:\\matlab6p5\\work\\xode.m", "xode/f")
    mwLocalFunctionTable save_local_function_table_
      = &_local_function_table_xode;
    mwArray dydx = mwArray::UNDEFINED;
    //
    // dydx = y - 2*x/y;
    //
    dydx = mwVa(y, "y") - 2 * mwVa(x, "x") / mwVa(y, "y");
    mwValidateOutput(dydx, 1, nargout_, "dydx", "xode/f");
    mclMlineFunctionReturn()
    return dydx;
    mclMlineExitFunctionReturn();
}

⌨️ 快捷键说明

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