mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
Remove LaTeX of matrix functions from util/latex.js
This commit is contained in:
parent
5b2b1de154
commit
52e169fae4
@ -37,7 +37,7 @@ function factory (type, config, load, typed) {
|
||||
* @param {... Array | Matrix} args Two or more matrices
|
||||
* @return {Array | Matrix} Concatenated matrix
|
||||
*/
|
||||
return typed('concat', {
|
||||
var concat = typed('concat', {
|
||||
// TODO: change signature to '...Array | Matrix, dim?' when supported
|
||||
'...Array | Matrix | number | BigNumber': function (args) {
|
||||
var i;
|
||||
@ -104,6 +104,10 @@ function factory (type, config, load, typed) {
|
||||
return asMatrix ? matrix(res) : res;
|
||||
}
|
||||
});
|
||||
|
||||
concat.toTex = '\\mathrm{${name}}\\left(${args}\\right)';
|
||||
|
||||
return concat;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -36,7 +36,7 @@ function factory (type, config, load, typed) {
|
||||
* @param {Array | Matrix} y Second vector
|
||||
* @return {Array | Matrix} Returns the cross product of `x` and `y`
|
||||
*/
|
||||
return typed('cross', {
|
||||
var cross = typed('cross', {
|
||||
'Matrix, Matrix': function (x, y) {
|
||||
return matrix(_cross(x.toArray(), y.toArray()));
|
||||
},
|
||||
@ -52,6 +52,10 @@ function factory (type, config, load, typed) {
|
||||
'Array, Array': _cross
|
||||
});
|
||||
|
||||
cross.toTex = '\\left(${args[0]}\\right)\\times\\left(${args[1]}\\right)';
|
||||
|
||||
return cross;
|
||||
|
||||
/**
|
||||
* Calculate the cross product for two arrays
|
||||
* @param {Array} x First vector
|
||||
|
||||
@ -37,7 +37,7 @@ function factory (type, config, load, typed) {
|
||||
* @param {Array | Matrix} x A matrix
|
||||
* @return {number} The determinant of `x`
|
||||
*/
|
||||
return typed('det', {
|
||||
var det = typed('det', {
|
||||
'any': function (x) {
|
||||
return object.clone(x);
|
||||
},
|
||||
@ -91,6 +91,10 @@ function factory (type, config, load, typed) {
|
||||
}
|
||||
});
|
||||
|
||||
det.toTex = '\\det\\left(${args[0]}\\right)';
|
||||
|
||||
return det;
|
||||
|
||||
/**
|
||||
* Calculate the determinant of a matrix
|
||||
* @param {Array[]} matrix A square, two dimensional matrix
|
||||
|
||||
@ -45,7 +45,7 @@ function factory (type, config, load, typed) {
|
||||
*
|
||||
* @returns {Matrix | Array} Diagonal matrix from input vector, or diagonal from input matrix.
|
||||
*/
|
||||
return typed('diag', {
|
||||
var diag = typed('diag', {
|
||||
// FIXME: simplify this huge amount of signatures as soon as typed-function supports optional arguments
|
||||
|
||||
'Array': function (x) {
|
||||
@ -97,6 +97,10 @@ function factory (type, config, load, typed) {
|
||||
}
|
||||
});
|
||||
|
||||
diag.toTex = '\\mathrm{${name}}\\left(${args}\\right)';
|
||||
|
||||
return diag;
|
||||
|
||||
/**
|
||||
* Creeate diagonal matrix from a vector or vice versa
|
||||
* @param {Array | Matrix} x
|
||||
|
||||
@ -29,7 +29,7 @@ function factory (type, config, load, typed) {
|
||||
* @param {Array | Matrix} y Second vector
|
||||
* @return {number} Returns the dot product of `x` and `y`
|
||||
*/
|
||||
return typed('dot', {
|
||||
var dot = typed('dot', {
|
||||
'Matrix, Matrix': function (x, y) {
|
||||
return _dot(x.toArray(), y.toArray());
|
||||
},
|
||||
@ -44,6 +44,10 @@ function factory (type, config, load, typed) {
|
||||
|
||||
'Array, Array': _dot
|
||||
});
|
||||
|
||||
dot.toTex = '\\left(${args[0]}\\cdot${args[1]}\\right)';
|
||||
|
||||
return dot;
|
||||
|
||||
/**
|
||||
* Calculate the dot product for two arrays
|
||||
|
||||
@ -37,7 +37,7 @@ function factory (type, config, load, typed) {
|
||||
*
|
||||
* @return {Matrix | Array | number} A matrix with ones on the diagonal.
|
||||
*/
|
||||
return typed('eye', {
|
||||
var eye = typed('eye', {
|
||||
'': function () {
|
||||
return (config.matrix === 'matrix') ? matrix([]) : [];
|
||||
},
|
||||
@ -79,6 +79,10 @@ function factory (type, config, load, typed) {
|
||||
}
|
||||
});
|
||||
|
||||
eye.toTex = '\\mathrm{${name}}\\left(${args}\\right)';
|
||||
|
||||
return eye;
|
||||
|
||||
function _eyeVector (size, format) {
|
||||
switch (size.length) {
|
||||
case 0: return format ? matrix(format) : [];
|
||||
|
||||
@ -24,7 +24,7 @@ function factory (type, config, load, typed) {
|
||||
* @param {Matrix | Array} x Matrix to be flattened
|
||||
* @return {Matrix | Array} Returns the flattened matrix
|
||||
*/
|
||||
return typed('flatten', {
|
||||
var flatten = typed('flatten', {
|
||||
'Array': function (x) {
|
||||
return _flatten(clone(x));
|
||||
},
|
||||
@ -35,6 +35,10 @@ function factory (type, config, load, typed) {
|
||||
return matrix(flat);
|
||||
}
|
||||
});
|
||||
|
||||
flatten.toTex = '\\mathrm{${name}}\\left(${args}\\right)';
|
||||
|
||||
return flatten;
|
||||
}
|
||||
|
||||
exports.name = 'flatten';
|
||||
|
||||
@ -199,6 +199,8 @@ function factory (type, config, load, typed) {
|
||||
}
|
||||
}
|
||||
|
||||
inv.toTex = '\\left(${args[0]}\\right)^{-1}';
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ function factory (type, config, load, typed) {
|
||||
*
|
||||
* @return {Array | Matrix | number} A matrix filled with ones
|
||||
*/
|
||||
return typed('ones', {
|
||||
var ones = typed('ones', {
|
||||
'': function () {
|
||||
return (config.matrix === 'array')
|
||||
? _ones([])
|
||||
@ -74,6 +74,10 @@ function factory (type, config, load, typed) {
|
||||
}
|
||||
});
|
||||
|
||||
ones.toTex = '\\mathrm{${name}}\\left(${args}\\right)';
|
||||
|
||||
return ones;
|
||||
|
||||
/**
|
||||
* Create an Array or Matrix with ones
|
||||
* @param {Array} size
|
||||
|
||||
@ -49,7 +49,7 @@ function factory (type, config, load, typed) {
|
||||
* @param {*} args Parameters describing the ranges `start`, `end`, and optional `step`.
|
||||
* @return {Array | Matrix} range
|
||||
*/
|
||||
return typed('range', {
|
||||
var range = typed('range', {
|
||||
// TODO: simplify signatures when typed-function supports default values and optional arguments
|
||||
|
||||
// TODO: a number or boolean should not be converted to string here
|
||||
@ -92,6 +92,10 @@ function factory (type, config, load, typed) {
|
||||
|
||||
});
|
||||
|
||||
range.toTex = '\\mathrm{${name}}\\left(${args}\\right)';
|
||||
|
||||
return range;
|
||||
|
||||
function _out(arr) {
|
||||
return config.matrix === 'array' ? arr : matrix(arr);
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ function factory (type, config, load, typed) {
|
||||
* @return {* | Array | Matrix} A resized clone of matrix `x`
|
||||
*/
|
||||
// TODO: rework resize to a typed-function
|
||||
return function resize (x, size, defaultValue) {
|
||||
var resize = function resize (x, size, defaultValue) {
|
||||
if (arguments.length != 2 && arguments.length != 3) {
|
||||
throw new ArgumentsError('resize', arguments.length, 2, 3);
|
||||
}
|
||||
@ -88,6 +88,10 @@ function factory (type, config, load, typed) {
|
||||
}
|
||||
};
|
||||
|
||||
resize.toTex = '\\mathrm{${name}}\\left(${args}\\right)';
|
||||
|
||||
return resize;
|
||||
|
||||
/**
|
||||
* Resize a string
|
||||
* @param {string} str
|
||||
|
||||
@ -28,7 +28,7 @@ function factory (type, config, load, typed) {
|
||||
* @param {boolean | number | Complex | Unit | string | Array | Matrix} x A matrix
|
||||
* @return {Array | Matrix} A vector with size of `x`.
|
||||
*/
|
||||
return typed('size', {
|
||||
var size = typed('size', {
|
||||
'Matrix': function (x) {
|
||||
// TODO: return the same matrix type as the input
|
||||
return matrix(x.size());
|
||||
@ -45,6 +45,10 @@ function factory (type, config, load, typed) {
|
||||
return (config.matrix === 'array') ? [] : matrix([]);
|
||||
}
|
||||
});
|
||||
|
||||
size.toTex = '\\mathrm{${name}}\\left(${args}\\right)';
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
exports.name = 'size';
|
||||
|
||||
@ -35,7 +35,7 @@ function factory (type, config, load, typed) {
|
||||
* @param {Matrix | Array} x Matrix to be squeezed
|
||||
* @return {Matrix | Array} Squeezed matrix
|
||||
*/
|
||||
return typed('squeeze', {
|
||||
var squeeze = typed('squeeze', {
|
||||
'Array': function (x) {
|
||||
return array.squeeze(object.clone(x));
|
||||
},
|
||||
@ -51,6 +51,10 @@ function factory (type, config, load, typed) {
|
||||
return object.clone(x);
|
||||
}
|
||||
});
|
||||
|
||||
squeeze.toTex = '\\mathrm{${name}}\\left(${args}\\right)';
|
||||
|
||||
return squeeze;
|
||||
}
|
||||
|
||||
exports.name = 'squeeze';
|
||||
|
||||
@ -41,7 +41,7 @@ function factory (type, config, load, typed) {
|
||||
* math.matrix elements will be left undefined.
|
||||
* @return {Array | Matrix | string} Either the retrieved subset or the updated matrix.
|
||||
*/
|
||||
return typed('subset', {
|
||||
var subset = typed('subset', {
|
||||
// get subset
|
||||
'Array, Index': function (value, index) {
|
||||
var m = matrix(value);
|
||||
@ -80,6 +80,10 @@ function factory (type, config, load, typed) {
|
||||
'string, Index, string, string': _setSubstring
|
||||
});
|
||||
|
||||
subset.toTex = '\\mathrm{${name}}\\left(${args}\\right)';
|
||||
|
||||
return subset;
|
||||
|
||||
/**
|
||||
* Retrieve a subset of a string
|
||||
* @param {string} str string from which to get a substring
|
||||
|
||||
@ -137,6 +137,8 @@ function factory (type, config, load, typed) {
|
||||
}
|
||||
throw new RangeError('Matrix must be square (size: ' + format(size) + ')');
|
||||
};
|
||||
|
||||
trace.toTex = '\\mathrm{tr}\\left(${args[0]}\\right)';
|
||||
|
||||
return trace;
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ var clone = require('../../util/object').clone;
|
||||
var format = require('../../util/string').format;
|
||||
|
||||
function factory (type, config, load, typed) {
|
||||
var latex = require('../../util/latex');
|
||||
|
||||
var matrix = load(require('../../type/matrix/function/matrix'));
|
||||
|
||||
@ -166,6 +167,8 @@ function factory (type, config, load, typed) {
|
||||
});
|
||||
};
|
||||
|
||||
transpose.toTex = '\\left(${args[0]}\\right)' + latex.operators['transpose'];
|
||||
|
||||
return transpose;
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ function factory (type, config, load, typed) {
|
||||
*
|
||||
* @return {Array | Matrix} A matrix filled with zeros
|
||||
*/
|
||||
return typed('zeros', {
|
||||
var zeros = typed('zeros', {
|
||||
'': function () {
|
||||
return (config.matrix === 'array')
|
||||
? _zeros([])
|
||||
@ -72,6 +72,10 @@ function factory (type, config, load, typed) {
|
||||
}
|
||||
});
|
||||
|
||||
zeros.toTex = '\\mathrm{${name}}\\left(${args}\\right)';
|
||||
|
||||
return zeros;
|
||||
|
||||
/**
|
||||
* Create an Array or Matrix with zeros
|
||||
* @param {Array} size
|
||||
|
||||
@ -116,25 +116,6 @@ exports.functions = {
|
||||
2: '\\left(\\left(${args[0]}\\right)${args[1]}\\right)'
|
||||
},
|
||||
|
||||
//matrix
|
||||
'concat': exports.defaultTemplate,
|
||||
'cross': '\\left(${args[0]}\\right)\\times\\left(${args[1]}\\right)',
|
||||
'det': '\\det\\left(${args[0]}\\right)',
|
||||
'diag': exports.defaultTemplate,
|
||||
'dot': '\\left(${args[0]}\\cdot${args[1]}\\right)',
|
||||
'eye': exports.defaultTemplate,
|
||||
'flatten': exports.defaultTemplate,
|
||||
'inv': '\\left(${args[0]}\\right)^{-1}',
|
||||
'ones': exports.defaultTemplate,
|
||||
'range': exports.defaultTemplate,
|
||||
'resize': exports.defaultTemplate,
|
||||
'size': exports.defaultTemplate,
|
||||
'squeeze': exports.defaultTemplate,
|
||||
'subset': exports.defaultTemplate,
|
||||
'trace': '\\mathrm{tr}\\left(${args[0]}\\right)',
|
||||
'transpose': '\\left(${args[0]}\\right)' + exports.operators['transpose'],
|
||||
'zeros': exports.defaultTemplate,
|
||||
|
||||
//probability
|
||||
'combinations': '\\binom{${args[0]}}{${args[1]}}',
|
||||
'distribution': exports.defaultTemplate,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user