recserrc.src

来自「没有说明」· SRC 代码 · 共 86 行

SRC
86
字号
/*
** recserrc.src
** (C) Copyright 1988-1998 by Aptech Systems, Inc.
** All Rights Reserved.
**
** This Software Product is PROPRIETARY SOURCE CODE OF APTECH
** SYSTEMS, INC.    This File Header must accompany all files using
** any portion, in whole or in part, of this Source Code.   In
** addition, the right to create such files is strictly limited by
** Section 2.A. of the GAUSS Applications License Agreement
** accompanying this Software Product.
**
** If you wish to distribute any portion of the proprietary Source
** Code, in whole or in part, you must first obtain written
** permission from Aptech Systems.
**
**> recserrc
**
**  Purpose:   Computes a recursive series involving division. Can be used to
**             convert from decimal to other number systems (radix conversion).
**
**  Format:    y = recserrc(x,z);
**
**  Inputs:    x    1xK or Kx1 matrix.
**
**             z    NxK matrix (the columns of z must equal the number of
**                  elements in x).
**
**  Output:    y    NxK matrix in which each column is a series generated by
**                  a recursion of the form:
**
**                                 y(1) = x mod z(1)
**                                 y(2) = trunc( x/z(1) ) mod z(2)
**                                 y(3) = trunc( x/z(2) ) mod z(3)
**                                  ...
**                                 y(n) = trunc( x/z(n-1 ) mod z(n)
**
**  Example:   x = 2|8|10; b = 2; format 1,0;
**             n = maxc( log(x)./log(b) ) + 1;
**             z = reshape( b, n, rows(x) );
**             y = rev( recserrc(x, z)  )' ;
**
**             The result, y, will contain in its rows (note that it is
**             transposed in the last step) the digits representing the
**             decimal numbers 2, 8, and 10 in base 2:
**
**                          0 0 1 0
**                          1 0 0 0
**                          1 0 1 0
**
** See Also:  recserar, recsercp
*/

proc recserrc(x,z);
    local n, k, y, rx, i, w, wi1;

    x = vec(x);
    rx = rows(x);
    n = rows(z);
    k = cols(z);

    if rx /= k;
        errorlog "ERROR: Number of elements in x must be the same as the"\
                 " number of columns in z.";
        end;
    endif;

    y = zeros(n,k);
    w = y;          /* need to store two results; return y */
    /* starting values for recursion */
    y[1,.] = x' % z[1,.];           /* remainder of division */
    w[1,.] = trunc( x' ./ z[1,.] );         /* integer part of division  */

    i = 2;
    do until i > n;

        wi1 = w[i-1,.];
        y[i,.] = wi1 % z[i,.];      /* remainder of division */
        w[i,.] = trunc( wi1 ./ z[i,.] );    /* integer part of division  */

        i = i + 1;
    endo;

    retp( y );
endp;

⌨️ 快捷键说明

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