Published
Edited
Oct 19, 2021
2 forks
Importers
16 stars
Insert cell
Insert cell
mlMatrix = require("ml-matrix@^6.8")
Insert cell
Insert cell
ones = Matrix.ones(5, 5)
Insert cell
Insert cell
viewof eye = pt(Matrix.eye(3, 4))
Insert cell
eye
Insert cell
viewof A = pt(new Matrix([[2, 3, 5], [4, 1, 6], [1, 3, 0]]))
Insert cell
viewof inverseA = pt(mlMatrix.inverse(A))
Insert cell
pt(A.mmul(inverseA))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
eigen = new mlMatrix.EigenvalueDecomposition(m)
Insert cell
pt(eigen.realEigenvalues)
Insert cell
pt(eigen.eigenvectorMatrix)
Insert cell
eigen.eigenvectorMatrix
Insert cell
Insert cell
// adapted from https://observablehq.com/@chitacan/handling-matrices#pt
function pt(matrix, MAXROWS = 8) {
const values = matrix.data || Array.from(matrix, (d) => [d]);
const data = values
//.toArray()
.slice(0, MAXROWS)
.map((row) =>
[...row]
.slice(0, MAXROWS)
.map(format)
.map((d, i) => (i === MAXROWS - 1 ? "…" : d))
.join(" & ")
)
.map((d, i) =>
i === MAXROWS - 1
? [...values[0]]
.slice(0, MAXROWS)
.map((d) => "…")
.join(" & ")
: d
)
.join(" \\\\ ");
const el = tex`
\left(\begin{matrix}
${data}
\end{matrix}\right)
`;
el.value = matrix;
return el;
}
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more