Exemplo n.º 1
0
/*
 * function y=myminus(a,b)
 */
static mxArray * Mmyminus(int nargout_, mxArray * a, mxArray * b) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_myminus);
    mxArray * y = NULL;
    mxArray * ans = NULL;
    mclCopyArray(&a);
    mclCopyArray(&b);
    /*
     * y=a-b;
     */
    mlfAssign(&y, mclMinus(mclVa(a, "a"), mclVa(b, "b")));
    /*
     * format rat;
     */
    mlfFormat(_mxarray0_, NULL);
    /*
     * y=rats(y);
     */
    mlfAssign(&y, mlfRats(mclVv(y, "y"), NULL));
    mclValidateOutput(y, 1, nargout_, "y", "myminus");
    mxDestroyArray(ans);
    mxDestroyArray(b);
    mxDestroyArray(a);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return y;
}
Exemplo n.º 2
0
/*
 * function r = rank(A,tol)
 */
static mxArray * Mrank(int nargout_, mxArray * A, mxArray * tol) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_rank);
    int nargin_ = mclNargin(2, A, tol, NULL);
    mxArray * r = mclGetUninitializedArray();
    mxArray * s = mclGetUninitializedArray();
    mclCopyArray(&A);
    mclCopyArray(&tol);
    /*
     * %RANK   Matrix rank.
     * %   RANK(A) provides an estimate of the number of linearly
     * %   independent rows or columns of a matrix A.
     * %   RANK(A,tol) is the number of singular values of A
     * %   that are larger than tol.
     * %   RANK(A) uses the default tol = max(size(A)) * norm(A) * eps.
     * 
     * %   Copyright 1984-2001 The MathWorks, Inc. 
     * %   $Revision: 5.10 $  $Date: 2001/04/15 12:01:33 $
     * 
     * s = svd(A);
     */
    mlfAssign(&s, mlfSvd(NULL, NULL, mclVa(A, "A"), NULL));
    /*
     * if nargin==1
     */
    if (nargin_ == 1) {
        /*
         * tol = max(size(A)') * max(s) * eps;
         */
        mlfAssign(
          &tol,
          mclMtimes(
            mclMtimes(
              mclVe(
                mlfMax(
                  NULL,
                  mlfCtranspose(
                    mclVe(mlfSize(mclValueVarargout(), mclVa(A, "A"), NULL))),
                  NULL,
                  NULL)),
              mclVe(mlfMax(NULL, mclVv(s, "s"), NULL, NULL))),
            _mxarray4_));
    /*
     * end
     */
    }
    /*
     * r = sum(s > tol);
     */
    mlfAssign(&r, mlfSum(mclGt(mclVv(s, "s"), mclVa(tol, "tol")), NULL));
    mclValidateOutput(r, 1, nargout_, "r", "rank");
    mxDestroyArray(s);
    mxDestroyArray(tol);
    mxDestroyArray(A);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return r;
}
Exemplo n.º 3
0
/*
 * function r=mrank(n)
 */
static mxArray * Mmrank(int nargout_, mxArray * n) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_mrank);
    mxArray * r = NULL;
    mxArray * ans = NULL;
    mxArray * k = NULL;
    mclCopyArray(&n);
    /*
     * r=zeros(n,1);
     */
    mlfAssign(&r, mlfZeros(mclVa(n, "n"), _mxarray0_, NULL));
    /*
     * for k=1:n
     */
    {
        int v_ = mclForIntStart(1);
        int e_ = mclForIntEnd(mclVa(n, "n"));
        if (v_ > e_) {
            mlfAssign(&k, _mxarray1_);
        } else {
            /*
             * r(k)=my_rank(magic(k));
             * end
             */
            for (; ; ) {
                mclIntArrayAssign1(
                  &r, mlfMy_rank(mlfMagic(mlfScalar(v_)), NULL), v_);
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&k, mlfScalar(v_));
        }
    }
    /*
     * r
     */
    mclPrintArray(mclVv(r, "r"), "r");
    mclValidateOutput(r, 1, nargout_, "r", "mrank");
    mxDestroyArray(k);
    mxDestroyArray(ans);
    mxDestroyArray(n);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return r;
}
Exemplo n.º 4
0
/*
 * function y=myeye(x)
 */
static mxArray * Mmyeye(int nargout_, mxArray * x) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_myeye);
    mxArray * y = NULL;
    mclCopyArray(&x);
    /*
     * y=eye(x);
     */
    mlfAssign(&y, mlfEye(mclVa(x, "x"), NULL));
    mclValidateOutput(y, 1, nargout_, "y", "myeye");
    mxDestroyArray(x);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return y;
}
Exemplo n.º 5
0
/*
 * function y=myrot(x)
 */
static mxArray * Mmyrot(int nargout_, mxArray * x) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_myrot);
    mxArray * y = NULL;
    mxArray * ans = NULL;
    mclCopyArray(&x);
    /*
     * y=inv(x);
     */
    mlfAssign(&y, mlfInv(mclVa(x, "x")));
    /*
     * format rat;
     */
    mlfFormat(_mxarray0_, NULL);
    /*
     * y=rats(y);
     */
    mlfAssign(&y, mlfRats(mclVv(y, "y"), NULL));
    mclValidateOutput(y, 1, nargout_, "y", "myrot");
    mxDestroyArray(ans);
    mxDestroyArray(x);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return y;
}
Exemplo n.º 6
0
/*
 * function theImage=gasket(numPoints)
 */
static mxArray * Mgasket(int nargout_, mxArray * numPoints) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_gasket);
    mxArray * theImage = NULL;
    mxArray * i = NULL;
    mxArray * theRand = NULL;
    mxArray * startPoint = NULL;
    mxArray * corners = NULL;
    mclCopyArray(&numPoints);
    /*
     * theImage =zeros(1000,1000);
     */
    mlfAssign(&theImage, mlfZeros(_mxarray0_, _mxarray0_, NULL));
    /*
     * corners=[866 1;1 500;866 1000];
     */
    mlfAssign(&corners, _mxarray1_);
    /*
     * startPoint=[866 1];
     */
    mlfAssign(&startPoint, _mxarray3_);
    /*
     * theRand=rand(numPoints,1);
     */
    mlfAssign(
      &theRand, mlfNRand(1, mclVa(numPoints, "numPoints"), _mxarray5_, NULL));
    /*
     * theRand=ceil(theRand*3);
     */
    mlfAssign(
      &theRand, mlfCeil(mclMtimes(mclVv(theRand, "theRand"), _mxarray6_)));
    /*
     * for i=1:numPoints
     */
    {
        int v_ = mclForIntStart(1);
        int e_ = mclForIntEnd(mclVa(numPoints, "numPoints"));
        if (v_ > e_) {
            mlfAssign(&i, _mxarray7_);
        } else {
            /*
             * startPoint=floor((corners(theRand(i),:)+startPoint)/2);
             * theImage(startPoint(1),startPoint(2))=1;
             * end
             */
            for (; ; ) {
                mlfAssign(
                  &startPoint,
                  mlfFloor(
                    mclMrdivide(
                      mclPlus(
                        mclArrayRef2(
                          mclVv(corners, "corners"),
                          mclIntArrayRef1(mclVv(theRand, "theRand"), v_),
                          mlfCreateColonIndex()),
                        mclVv(startPoint, "startPoint")),
                      _mxarray8_)));
                mclArrayAssign2(
                  &theImage,
                  _mxarray5_,
                  mclIntArrayRef1(mclVv(startPoint, "startPoint"), 1),
                  mclIntArrayRef1(mclVv(startPoint, "startPoint"), 2));
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&i, mlfScalar(v_));
        }
    }
    mclValidateOutput(theImage, 1, nargout_, "theImage", "gasket");
    mxDestroyArray(corners);
    mxDestroyArray(startPoint);
    mxDestroyArray(theRand);
    mxDestroyArray(i);
    mxDestroyArray(numPoints);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return theImage;
}