📄 xodes.cpp
字号:
//
// MATLAB Compiler: 3.0
// Date: Mon Jul 02 23:52:29 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/xODEs.m"
//
#include "xodes.hpp"
#include "libmatlbm.hpp"
#include "libmmfile.hpp"
static double _array0_[2] = { 0.0, 1.0 };
static double _array1_[6] = { 0.0, .2, .4, .6, .8, 1.0 };
void InitializeModule_xodes() {
}
void TerminateModule_xodes() {
}
static mwArray xodes_f(mwArray x = mwArray::DIN, mwArray y = mwArray::DIN);
#ifdef __cplusplus
extern "C"
#endif
void mlxXodes_f(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]);
static void Mxodes();
static mwArray Mxodes_f(int nargout_, mwArray x, mwArray y);
static mexFunctionTableEntry local_function_table_[1]
= { { "f", mlxXodes_f, 2, 1, NULL } };
_mexLocalFunctionTable _local_function_table_xodes
= { 1, local_function_table_ };
//
// The function "xodes" contains the normal interface for the "xodes"
// M-function from file "d:\matlab6p5\work\xodes.m" (lines 1-25). This function
// processes any input arguments and passes them to the implementation version
// of the function, appearing above.
//
void xodes() {
Mxodes();
}
//
// The function "mlxXodes" contains the feval interface for the "xodes"
// M-function from file "d:\matlab6p5\work\xodes.m" (lines 1-25). The feval
// function calls the implementation version of xodes through this function.
// This function processes any input arguments and passes them to the
// implementation version of the function, appearing above.
//
void mlxXodes(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
MW_BEGIN_MLX();
{
if (nlhs > 0) {
error(
mwVarargin(
mwArray(
"Run-time Error: File: xodes Line: 1 Column: 1"
" The function \"xodes\" was called with more "
"than the declared number of outputs (0).")));
}
if (nrhs > 0) {
error(
mwVarargin(
mwArray(
"Run-time Error: File: xodes Line: 1 Column: 1"
" The function \"xodes\" was called with more "
"than the declared number of inputs (0).")));
}
Mxodes();
}
MW_END_MLX();
}
//
// The function "xodes_f" contains the normal interface for the "xodes/f"
// M-function from file "d:\matlab6p5\work\xodes.m" (lines 25-27). This
// function processes any input arguments and passes them to the implementation
// version of the function, appearing above.
//
static mwArray xodes_f(mwArray x, mwArray y) {
int nargout = 1;
mwArray dydx = mwArray::UNDEFINED;
dydx = Mxodes_f(nargout, x, y);
return dydx;
}
//
// The function "mlxXodes_f" contains the feval interface for the "xodes/f"
// M-function from file "d:\matlab6p5\work\xodes.m" (lines 25-27). The feval
// function calls the implementation version of xodes/f through this function.
// This function processes any input arguments and passes them to the
// implementation version of the function, appearing above.
//
void mlxXodes_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: xodes/f Line: 25 Column: "
"1 The function \"xodes/f\" was called with more"
" than the declared number of outputs (1).")));
}
if (nrhs > 2) {
error(
mwVarargin(
mwArray(
"Run-time Error: File: xodes/f Line: 25 Column:"
" 1 The function \"xodes/f\" was called with mo"
"re 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] = Mxodes_f(nlhs, mprhs[0], mprhs[1]);
plhs[0] = mplhs[0].FreezeData();
}
MW_END_MLX();
}
//
// The function "Mxodes" is the implementation version of the "xodes"
// M-function from file "d:\matlab6p5\work\xodes.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 xODEs
//
static void Mxodes() {
mclMlineEnterFunction("d:\\matlab6p5\\work\\xodes.m", "xodes")
mwLocalFunctionTable save_local_function_table_
= &_local_function_table_xodes;
mwArray y2 = mwArray::UNDEFINED;
mwArray x2 = mwArray::UNDEFINED;
mwArray y1 = mwArray::UNDEFINED;
mwArray x1 = mwArray::UNDEFINED;
mwArray y0 = mwArray::UNDEFINED;
mwArray ans = mwArray::UNDEFINED;
//
// % xODEs.m
// % Demonstrate how to use ode45() and ode23() to solve a set of simultaneous ODE equations
// %
// % 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();
//
//
// y0 = [0 1];
//
mclMline(13);
y0 = mwArray(1, 2, _array0_, (double *)NULL);
//
// [x1,y1] = ode45(@f,[0:0.2:1],y0);
//
mclMline(14);
Node45(
0,
mwVarargout(x1, y1),
mwArray(mlxXodes_f, "f"),
mwArray(1, 6, _array1_, (double *)NULL),
mwVv(y0, "y0"));
//
// [x2,y2] = ode23(@f,[0:0.2:1],y0);
//
mclMline(15);
Node23(
0,
mwVarargout(x2, y2),
mwArray(mlxXodes_f, "f"),
mwArray(1, 6, _array1_, (double *)NULL),
mwVv(y0, "y0"));
//
//
// disp('Results by using ode45():')
//
mclMline(17);
disp(mwArray("Results by using ode45()\243\272"));
//
// disp(' x y(1) y(2)')
//
mclMline(18);
disp(mwArray(" x y(1) y(2)"));
//
// disp([x1 y1])
//
mclMline(19);
disp(horzcat(mwVarargin(mwVv(x1, "x1"), mwVv(y1, "y1"))));
//
// disp('Results by using ode23():')
//
mclMline(20);
disp(mwArray("Results by using ode23()\243\272"));
//
// disp(' x y(1) y(2)')
//
mclMline(21);
disp(mwArray(" x y(1) y(2)"));
//
// disp([x2 y2])
//
mclMline(22);
disp(horzcat(mwVarargin(mwVv(x2, "x2"), mwVv(y2, "y2"))));
//
//
// % ------------------------------------------------------------------
//
mclMline(24);
mclMlineExitFunction();
}
//
// The function "Mxodes_f" is the implementation version of the "xodes/f"
// M-function from file "d:\matlab6p5\work\xodes.m" (lines 25-27). 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) % Define simultaneous ODE equations
//
static mwArray Mxodes_f(int nargout_, mwArray x, mwArray y) {
mclMlineEnterFunction("d:\\matlab6p5\\work\\xodes.m", "xodes/f")
mwLocalFunctionTable save_local_function_table_
= &_local_function_table_xodes;
mwArray dydx = mwArray::UNDEFINED;
//
// dydx = [3*y(1) + 2*y(2); 4*y(1)+y(2)];
//
mclMline(26);
dydx
= vertcat(
mwVarargin(
3 * mwVa(y, "y")(1) + 2 * mwVa(y, "y")(2),
4 * mwVa(y, "y")(1) + mwVa(y, "y")(2)));
mwValidateOutput(dydx, 1, nargout_, "dydx", "xodes/f");
mclMlineFunctionReturn()
return dydx;
mclMlineExitFunctionReturn();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -