mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
var deepMap = require('../../utils/collection/deepMap');
|
|
|
|
function factory (type, config, load, typed) {
|
|
/**
|
|
* Compute the complex conjugate of a complex value.
|
|
* If `x = a+bi`, the complex conjugate of `x` is `a - bi`.
|
|
*
|
|
* For matrices, the function is evaluated element wise.
|
|
*
|
|
* Syntax:
|
|
*
|
|
* math.conj(x)
|
|
*
|
|
* Examples:
|
|
*
|
|
* math.conj(math.complex('2 + 3i')); // returns Complex 2 - 3i
|
|
* math.conj(math.complex('2 - 3i')); // returns Complex 2 + 3i
|
|
* math.conj(math.complex('-5.2i')); // returns Complex 5.2i
|
|
*
|
|
* See also:
|
|
*
|
|
* re, im, arg, abs
|
|
*
|
|
* @param {number | BigNumber | Complex | Array | Matrix} x
|
|
* A complex number or array with complex numbers
|
|
* @return {number | BigNumber | Complex | Array | Matrix}
|
|
* The complex conjugate of x
|
|
*/
|
|
var conj = typed('conj', {
|
|
'number': function (x) {
|
|
return x;
|
|
},
|
|
|
|
'BigNumber': function (x) {
|
|
return x;
|
|
},
|
|
|
|
'Complex': function (x) {
|
|
return new type.Complex(x.re, -x.im);
|
|
},
|
|
|
|
'Array | Matrix': function (x) {
|
|
return deepMap(x, conj);
|
|
}
|
|
});
|
|
|
|
conj.toTex = '\\left(${args[0]}\\right)^*';
|
|
|
|
return conj;
|
|
}
|
|
|
|
exports.name = 'conj';
|
|
exports.factory = factory;
|