Mathematical Functions
LINGO offers a number of standard, mathematical functions. These functions return a single result based on one or more scalar arguments. These functions are listed below.
Note: | Not all mathematical functions are defined over all argument values. For example, @LOG( X - 5) is not defined for values of X less-than-or-equal-to 5. In such cases, it may be helpful to bound variables so that all functions are defined, otherwise the solver may return a numeric error. For our @LOG example here, we would want to add a bound statement like @BND( 5.001, X, 100), to force X to lie within the range 5.001 and 100, forcing the @LOG function to be defined over the entire range for X. |
@ABS( X)
Returns the absolute value of X.
@ACOS( X)
Returns the inverse cosine, or arccosine, of X, where X is an angle in radians.
@ACOSH( X)
Returns the inverse hyperbolic cosine of X, where X is an angle in radians.
@ASIN( X)
Returns the inverse sine, or arcsine, of X, where X is an angle in radians.
@ASINH( X)
Returns the inverse hyperbolic sine of X, where X is an angle in radians.
@ATAN( X)
Returns the inverse tangent, or arctangent, of X, where X is an angle in radians.
@ATAN2( X, Y)
Returns the inverse tangent of Y/X.
@ATANH( X)
Returns the inverse hyperbolic tangent of X, where X is an angle in radians.
@COS( X)
Returns the cosine of X, where X is an angle in radians.
@COSH( X)
Returns the hyperbolic cosine of X, where X is an angle in radians.
@EXP( X)
Returns e (2.718281...) raised to the power X.
@FLOOR( X)
This returns the integer part of X. To be specific, if X ≥ 0, @FLOOR returns the largest integer, I, such that I ≤ X. If X is negative, @FLOOR returns the most negative integer, I, such that I ≥ X.
@INT( X)
This returns the integer part of X. To be specific, if X ≥ 0, @INT returns the largest integer, I, such that I ≤ X. If X is negative, @INT returns the largest negative integer, I, such that X ≥ I.
@INTEGRAL( PROCEDURE, X, XL, XU, Y)
This function performs numeric integration using a variant of Simpson's Rule. Argument PROCEDURE is the name of a procedure which calculates the function to be integrated. The function's value should be placed in Y in the specified procedure. The integral will be taken with respect to X over the interval [XL,XU]. At present, @INTEGRAL may only be used in calc sections.
Example 1:
In this example, we illustrate how to compute the integral of the standard normal distribution over the interval [-5,1.645].
MODEL:
! Takes the integral of the standard normal
distribution over the interval [-5,1.645];
PROCEDURE NORMAL:
Y = @EXP( -X * X / 2) / (( 2 * @PI()) ^ 0.5);
ENDPROCEDURE
CALC:
PROB = @INTEGRAL( NORMAL, X, -5, 1.645, Y);
ENDCALC
END
@LGM( X)
Returns the natural (base e) logarithm of the gamma function of X (i.e., log of (X - 1)!). It is extended to non-integer values of X by linear interpolation.
@LOG( X)
Returns the natural logarithm of X.
@LOG10( X)
Returns the base-10 logarithm of X.
@LOGB( X, B)
Returns the base B logarithm of X, e.g., @LOGB( 8, 2) = 3.
@MOD( X, Y)
Returns the value of X modulo Y, or, in other words, the remainder of an integer divide of X by Y.
@PI()
Returns the value of PI, i.e., 3.14159265.... |
@POW( X, Y)
Returns the value of X raised to the Y power. |
@ROUND( X, N)
The @ROUND function rounds X to the closest number to X having N digits. For example, if X is equal to 2.576 and N is 2, then @ROUND( X, N) will return 2.58. If X is equal to -2.576 and N is 2, then @ROUND( X, N) will return -2.58.
@ROUNDDOWN( X, N)
The @ROUNDDOWN function rounds X down (towards 0) to the closest number to X having N digits. For example, if X is equal to 2.576 and N is 2, then @ROUNDDOWN( X, N) will return 2.57. If X is equal to -2.576 and N is 2, then @ROUNDDOWN( X, N) will return -2.57.
@ROUNDUP( X, N)
The @ROUNDUP function rounds X up (away from 0) to the closest number to X having N digits. For example, if X is equal to 2.576 and N is 2, then @ROUNDUP( X, N) will return 2.58. If X is equal to -2.576 and N is 2, then @ROUNDUP( X, N) will return -2.58.
@SIGN( X)
Returns -1 if X < 0, 0 if X = 0 and +1 if X > 0.
@SIN( X)
Returns the sine of X, where X is the angle in radians.
@SINH( X)
Returns the hyperbolic sine of X, where X is an angle in radians.
@SMAX( X1, X2,..., XN)
Returns the maximum value of X1, X2, ..., and XN.
@SMIN( X1, X2,..., XN)
Returns the minimum value of X1, X2, ..., and XN.
@SQR( X)
Returns the value of X squared.
@SQRT( X)
Returns the square root of X.
@TAN( X)
Returns the tangent of X, where X is the angle in radians.
@TANH( X)
Returns the hyperbolic tangent of X, where X is an angle in radians.