Cosine of fi object
y = cos(theta)
y = cos(theta) returns the cosine of fi input theta using a table-lookup algorithm.
theta can be a real-valued, signed or unsigned scalar, vector, matrix, or N-dimensional array containing the fixed-point angle values in radians. Valid data types of theta are:
y is the cosine of theta. y is a signed, fixed-point number in the range [-1,1]. It has a 16-bit word length and 15-bit fraction length (numerictype(1,16,15)). This cosine calculation is accurate only to within the top 16 most-significant bits of the input.
Calculate the cosine of fixed-point input values.
theta = fi([0,pi/4,pi/3,pi/2,(2*pi)/3,(3*pi)/4,pi]) theta = 0 0.7854 1.0472 1.5708 2.0944 2.3562 3.1416 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 13 y = cos(theta) y = 1.0000 0.7072 0.4999 0.0001 -0.4999 -0.7070 -1.0000 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 15
The cosine of angle Θ is defined as
The cos function computes the cosine of fixed-point input using an 8-bit lookup table as follows:
Cast the input to a 16-bit stored integer value, using the 16 most-significant bits.
Perform a modulo 2π, so the input is in the range [0,2π) radians.
Compute the table index, based on the 16-bit stored integer value, normalized to the full uint16 range.
Use the 8 most-significant bits to obtain the first value from the table.
Use the next-greater table value as the second value.
Use the 8 least-significant bits to interpolate between the first and second values, using nearest-neighbor linear interpolation.
The cos function ignores and discards any fimath attached to the input, theta. The output, y, is always associated with the default fimath.