Skip to content

Commit 0edfb05

Browse files
committed
More examples for migration to V15.
1 parent d1c135b commit 0edfb05

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

docs/datatypes/matrices.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ const m = math.matrix([[1, 2, 3], [4, 5, 6]])
364364

365365

366366
> **Tip:**
367-
> If you want to always get a scalar value, use scalar indices.
368-
>
367+
> If you want to get a scalar value, use scalar indices.
369368
> If you want to preserve dimensions, use array, matrix or range indices.
370369
371370
## Getting and setting a value in a matrix

docs/expressions/syntax.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ math applications.*
682682

683683
*IMPORTANT: Matrix indexing behaves differently depending on the type of input.
684684
If an index for a dimension is a scalar (single value), that dimension is
685-
removed from the result.*
685+
removed from the result. For more information of the changes go to [Migrate to V15](../datatypes/matrices.md#migrate-to-v15).*
686686

687687
```js
688688
parser = math.parser()
@@ -705,6 +705,29 @@ parser.evaluate('d[2, 1:end]') // Matrix, [43, 50]
705705
parser.evaluate('c[end - 1 : -1 : 2]') // Matrix, [8, 7, 6]
706706
```
707707

708+
#### Matrix Migration examples
709+
710+
With v15, matrix indexing has changed to be more consistent and predictable. In v14, using a scalar index would sometimes reduce the dimensionality of the result. In v15, if you want to preserve dimensions, use array, matrix, or range indices. If you want a scalar value, use scalar indices.
711+
712+
For example:
713+
714+
```js
715+
parser = math.parser()
716+
parser.evaluate('m = [1, 2, 3; 4, 5, 6]')
717+
```
718+
719+
| v14 code | v15 equivalent code | Result |
720+
|-------------------------|-------------------------------|--------------------|
721+
| `m[1:2, 2:3]` | No change needed | `[[2, 3], [5, 6]]` |
722+
| `m[2, 2:3]` | `m[[2], 2:3]` | `[[5, 6]]` |
723+
| `m[1:2, 3]` | `m[1:2, [3]]` | `[[3], [6]]` |
724+
| `m[2, 3]` | No change needed | `6` |
725+
726+
> **Tip:**
727+
> If you want to always get a scalar value, use scalar indices.
728+
> If you want to preserve dimensions, use array, matrix or range indices.
729+
730+
708731
## Objects
709732

710733
Objects in math.js work the same as in languages like JavaScript and Python.

0 commit comments

Comments
 (0)