sec
Use the sec() function to calculate the secant of a numeric value specified in radians. The secant is the reciprocal of the cosine function.
Syntax
sec(<numeric_expression>)Parameters
numeric_expression
integer, float
Yes
The angle in radians for which to calculate the secant. The value must not be an odd multiple of p/2.
Returns
Type: float
Description: The sec() function returns the secant of the input angle, which is equivalent to 1 / cos(x). If the input is null, the function returns null.
Usage notes
Input type: XQL doesn't support NaN or infinite values as input and these value types also can not be returned.
Valid Input Range: The
sec()function accepts any real number except values wherecos(x) = 0(i.e., odd multiples of p/2), where the secant is undefined.Undefined Values: At odd multiples of p/2 (for example, p/2, 3p/2), the function returns
infinity,NaN, ornullsince the secant is undefined at these points.Null Handling: If the input expression is
null, the function returnsnull.Relationship:
sec(x) = 1 / cos(x).Result Range: The result is always = -1 or = 1 (never between -1 and 1).
Common Use Cases: This function is typically used within the
alterstage for trigonometric calculations, optics computations, and engineering analysis.
Examples
Example 1: Calculate secant of literal values
Goal: Calculate the secant for specific radian values to verify known mathematical results.
XQL code:
Explanation: sec(0) returns 1.0 (since cos(0) = 1), sec(p) returns -1.0 (since cos(p) = -1), and sec(1) returns approximately 1.8508.
Output:
1.0
-1.0
1.85082
Example 2: Calculate secant from a field value
Goal: Calculate the secant of values stored in a dataset field.
XQL code:
Explanation: This query computes the secant for each value in the numeric_value field and stores the result in sec_val.
Output:
101
0.0
1.0
102
1.0
1.85082
103
3.14159
-1.0
Example 3: Verify secant as reciprocal of cosine
Goal: Demonstrate that sec(x) equals 1 / cos(x) by computing both and comparing.
XQL code:
Explanation: This query computes both sec(numeric_value) and 1 / cos(numeric_value) to verify they produce the same result, confirming the mathematical identity sec(x) = 1 / cos(x).
Output:
101
0.0
1.0
1.0
102
1.0
1.85082
1.85082
103
3.14159
-1.0
-1.0
Related articles
Last updated
Was this helpful?
