rational(x, a, b) or rational(x, a) or rational(x,,b), x REAL or a structure with REAL components, a and b REAL vectors |

rational(x,a,b) computes a rational function of the REAL vector, matrix, or array x, with coefficients for the numerator and denominator polynomials in REAL vectors a and b. The result is REAL with the same size and shape as x. The rational function computed is (a[1] + a[2]*x + a[3]*x^2+ ... )/(b[1] + b[2]*x + b[3]*x^2+ ... ) . If a or b is omitted, it is construed to represent the constant 1. For example, rational(x,a), rational(x,a,), and rational(x,a,1) are equivalent and compute a polynomial in x, and rational(x,,b), and rational(x,1,b) are equivalent and compute the reciprocal of a polynomial in x. x can also be a structure, all of whose non-structure components are REAL, in which case the result is a similar structure. An important use of rational() is in writing macros to compute mathematical functions that are not directly available in MacAnova but which can be approximated by rational functions. For example Cmd> cumnor1 <- macro("@x <- $1; @posx <- @x > 0 @posx - (@posx - .5)*rational(abs(@x),1,\\ vector(1,.196854,.115194,.000355,.019527))^4", dollar:T) creates macro cumnor1() which uses an approximation due to Hastings to cumpute cumulative normal probabilities. For more elaborate use, see macros i0() and i1() in file Math.mac distributed with MacAnova. See topics macro() and 'macros'.

Gary Oehlert 2003-01-15