📄 frac_tree.c
字号:
/*
* MATLAB Compiler: 2.0
* Date: Tue Apr 18 07:48:49 2000
* Arguments: "-x" "frac_tree.m"
*/
#include "frac_tree.h"
/*
* The function "Mfrac_tree" is the implementation version of the "frac_tree"
* M-function from file
* "C:\Xue.Dy\BOOKS\MATLAB\mat5progs\mat5files\frac_tree.m" (lines 1-14). 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(x0,y0,v,N)
*/
static mxArray * Mfrac_tree(mxArray * * y,
int nargout_,
mxArray * x0,
mxArray * y0,
mxArray * v,
mxArray * N) {
mxArray * x = mclGetUninitializedArray();
mxArray * i = mclGetUninitializedArray();
mclForLoopIterator iterator_0;
mxArray * vv = mclGetUninitializedArray();
mclValidateInputs("frac_tree", 4, &x0, &y0, &v, &N);
/*
* 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", 2, nargout_, &x, y);
mxDestroyArray(i);
mxDestroyArray(vv);
return x;
}
/*
* The function "mlfFrac_tree" contains the normal interface for the
* "frac_tree" M-function from file
* "C:\Xue.Dy\BOOKS\MATLAB\mat5progs\mat5files\frac_tree.m" (lines 1-14). This
* function processes any input arguments and passes them to the implementation
* version of the function, appearing above.
*/
mxArray * mlfFrac_tree(mxArray * * y,
mxArray * x0,
mxArray * y0,
mxArray * v,
mxArray * N) {
int nargout = 1;
mxArray * x = mclGetUninitializedArray();
mxArray * y__ = mclGetUninitializedArray();
mlfEnterNewContext(1, 4, y, x0, y0, v, N);
if (y != NULL) {
++nargout;
}
x = Mfrac_tree(&y__, nargout, x0, y0, v, N);
mlfRestorePreviousContext(1, 4, y, x0, y0, v, N);
if (y != NULL) {
mclCopyOutputArg(y, y__);
} else {
mxDestroyArray(y__);
}
return mlfReturnValue(x);
}
/*
* The function "mlxFrac_tree" contains the feval interface for the "frac_tree"
* M-function from file
* "C:\Xue.Dy\BOOKS\MATLAB\mat5progs\mat5files\frac_tree.m" (lines 1-14). The
* feval function calls the implementation version of frac_tree through this
* function. This function processes any input arguments and passes them to the
* implementation version of the function, appearing above.
*/
void mlxFrac_tree(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
mxArray * mprhs[4];
mxArray * mplhs[2];
int i;
if (nlhs > 2) {
mlfError(
mxCreateString(
"Run-time Error: File: frac_tree Line: 1 Column:"
" 0 The function \"frac_tree\" was called with m"
"ore than the declared number of outputs (2)"));
}
if (nrhs > 4) {
mlfError(
mxCreateString(
"Run-time Error: File: frac_tree Line: 1 Column:"
" 0 The function \"frac_tree\" was called with m"
"ore than the declared number of inputs (4)"));
}
for (i = 0; i < 2; ++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]
= Mfrac_tree(&mplhs[1], 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 < 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 + -