vers function

dynamic vers(
  1. dynamic x
)

Versine function

The versine or versine or versed sine of an angle is 1 − cos(θ). It's rarely used in modern mathematics but can be found in various historical contexts.

Example:

print(vers(math.pi / 2));  // Output: 1.0
print(vers(math.pi / 4));  // Output: 0.2928932188134524
print(vers(math.pi / 6));  // Output: 0.1339745962155613

The output is 1.0 because the versine of π/2 (or 90 degrees) is 1.

Example 2:

print(vers(Matrix.identity(2))); // Output: [[1.0, 0.0], [0.0, 1.0]]

Implementation

dynamic vers(dynamic x) {
  if (x is num || x is Complex) {
    return x is num ? 1 - math.cos(x) : Complex.one() - cos(x);
  } else if (x is Matrix) {
    return MatrixFunctions(x).vers();
  } else {
    throw ArgumentError('Input should be either num or Complex');
  }
}