Reputation: 21
I want to find the inverse of a matrix with javascript; how can i do that??
I already tried downloading the mathjs library but i dont know how to initiate it
Upvotes: 2
Views: 93
Reputation: 6711
The website has a starting example, reproduced below.
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="math.js | basic usage">
<title>math.js | basic usage</title>
<script src="https://unpkg.com/mathjs/lib/browser/math.js"></script>
</head>
<body>
<script>
// basic usage of math.js
//
// website: http://mathjs.org
// docs: http://mathjs.org/docs
// examples: http://mathjs.org/examples
// functions and constants
print(math.round(math.e, 3)); // 2.718
print(math.atan2(3, -3) / math.pi); // 0.75
print(math.log(10000, 10)); // 4
print(math.sqrt(-4)); // 2i
print(math.pow([[-1, 2], [3, 1]], 2)); // [[7, 0], [0, 7]]
print(math.derivative('x^2 + x', 'x')); // 2 * x + 1
// expressions
print(math.evaluate('12 / (2.3 + 0.7)')); // 4
print(math.evaluate('12.7 cm to inch')); // 5 inch
print(math.evaluate('9 / 3 + 2i')); // 3 + 2i
print(math.evaluate('det([-1, 2; 3, 1])')); // -7
// chaining
var a = math.chain(3)
.add(4)
.multiply(2)
.done();
print(a); // 14
// helper function to output formatted results.
function print(value) {
var precision = 14;
document.write(math.format(value, precision) + '<br>');
}
</script>
</body>
</html>
Upvotes: 0