mathjs/examples/browser/basic_usage.html

40 lines
1021 B
HTML

<!DOCTYPE html>
<html>
<head>
<title>math.js | basic usage</title>
<script type="text/javascript" src="../../dist/math.js"></script>
</head>
<body>
<script>
// create an instance of math.js
var math = mathjs();
function print(value) {
var precision = 5;
document.write(math.format(value, precision) + '<br>');
}
// functions and constants
print(math.round(math.e, 3)); // 2.718
print(math.atan2(3, -3) / math.pi); // 0.75
print(math.log(1000, 10)); // 3
print(math.sqrt(-4)); // 2i
print(math.pow([[-1, 2], [3, 1]], 2)); // [[7, 0], [0, 7]]
// expressions
print(math.eval('12 / (2.3 + 0.7)')); // 4
print(math.eval('5.08 cm to inch')); // 2 inch
print(math.eval('9 / 3 + 2i')); // 3 + 2i
print(math.eval('det([-1, 2; 3, 1])')); // -7
// chained operations
var a = math.select(3)
.add(4)
.multiply(2)
.done();
print(a); // 14
</script>
</body>
</html>