mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
'use strict'
|
|
|
|
import { factory } from '../../utils/factory'
|
|
import { deepMap } from '../../utils/collection'
|
|
|
|
const name = 'asec'
|
|
const dependencies = ['typed', 'config', 'type.Complex', 'type.BigNumber']
|
|
|
|
export const createAsec = factory(name, dependencies, ({ typed, config, type: { Complex, BigNumber } }) => {
|
|
/**
|
|
* Calculate the inverse secant of a value. Defined as `asec(x) = acos(1/x)`.
|
|
*
|
|
* For matrices, the function is evaluated element wise.
|
|
*
|
|
* Syntax:
|
|
*
|
|
* math.asec(x)
|
|
*
|
|
* Examples:
|
|
*
|
|
* math.asec(0.5) // returns 1.0471975511965979
|
|
* math.asec(math.sec(1.5)) // returns 1.5
|
|
*
|
|
* math.asec(2) // returns 0 + 1.3169578969248166 i
|
|
*
|
|
* See also:
|
|
*
|
|
* acos, acot, acsc
|
|
*
|
|
* @param {number | Complex | Array | Matrix} x Function input
|
|
* @return {number | Complex | Array | Matrix} The arc secant of x
|
|
*/
|
|
const asec = typed(name, {
|
|
'number': function (x) {
|
|
if (x <= -1 || x >= 1 || config().predictable) {
|
|
return Math.acos(1 / x)
|
|
}
|
|
return new Complex(x, 0).asec()
|
|
},
|
|
|
|
'Complex': function (x) {
|
|
return x.asec()
|
|
},
|
|
|
|
'BigNumber': function (x) {
|
|
return new BigNumber(1).div(x).acos()
|
|
},
|
|
|
|
'Array | Matrix': function (x) {
|
|
return deepMap(x, asec)
|
|
}
|
|
})
|
|
|
|
asec.toTex = { 1: `\\sec^{-1}\\left(\${args[0]}\\right)` }
|
|
|
|
return asec
|
|
})
|