mathjs/examples/browser/basic_usage.html.md
2018-06-02 12:08:10 +02:00

52 lines
1.2 KiB
Markdown

---
layout: default
---
# Basic usage
File: [basic_usage.html](basic_usage.html) (click for a live demo)
```html
<!DOCTYPE html>
<html>
<head>
<title>math.js | basic usage</title>
<script src="https://unpkg.com/mathjs@4.4.2/dist/math.min.js"></script>
</head>
<body>
<script>
function print(value) {
var precision = 14;
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(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.eval('12 / (2.3 + 0.7)')); // 4
print(math.eval('12.7 cm to inch')); // 5 inch
print(math.eval('9 / 3 + 2i')); // 3 + 2i
print(math.eval('det([-1, 2; 3, 1])')); // -7
// chained operations
var a = math.chain(3)
.add(4)
.multiply(2)
.done();
print(a); // 14
</script>
</body>
</html>
```
<!-- Note: This file is automatically generated. Changes made in this file will be overridden. -->