recsercp

Purpose

Computes a recursive series involving products. Can be used to compute cumulative products, to evaluate polynomials using Horner’s rule, and to convert from base b representations of numbers to decimal representations among other things.

Format

y = recsercp(x, z)
Parameters:
  • x (NxK or 1xK matrix) – data
  • z (NxK or 1xK matrix) – data
Returns:

y (NxK matrix) –

Each column is a series generated by a recursion of the form:

y(1) = x(1) + z(1)
y(t) = y(t - 1) * x(t) + z(t), t=2,...N

Examples

// Scalar x
x = 4;

// C
c = { 3, 4, -2, 6, 4, 2 } ;

// Used to normalize first element in c
c1 = c[1, .];

// Compute a recursive series
y = recsercp(x, trimr(c ./ c1, 1, 0));

// Last element in p
// transformed for normalization
n = rows(c) - 1;
p = c1 .* y[n, .];

If x is a scalar and c is an (N+1)x1 vector, the result p will contain the value of the polynomial whose coefficients are given in c. That is:

p = c[1,.].*x^n + c[2,.].*x^(n-1) + ... + c[n+1,.];

Note that both x and c could contain more than 1 column, and then this code would evaluate the entire set of polynomials at the same time. Note also that if x = 2, and if c contains the digits of the binary representation of a number, then p will be the decimal representation of that number.

Remarks

The following GAUSS code could be used to emulate recsercp() when the number of rows in x and z is the same:

/* assume here that rows(z) is also n */
n = rows(x);
y = zeros(n, 1);
y[1,.] = x[1,.] + z[1,.];

i = 2;
do until i > n;
    y[i, .] = y[i-1, .] .* x[i, .] + z[i, .];
    i = i + 1;
endo;

Note that \(K\) series can be computed simultaneously, since x and z can have \(K\) columns (they must both have the same number of columns).

recsercp() allows either x or z to have only 1 row.

recsercp(x, 0) will produce the cumulative products of the elements in x.

See also

Functions recserar(), recserrc(), recserVAR()