Public
Edited
Feb 8, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = {
const { mat: m } = mat;

const types = ["A", "B"];
const displayMatrix = [];
for (let i = 0; i < 2; ++i) {
for (let j = 0; j < 2; ++j) {
displayMatrix.push({
x: types[i] + "r",
y: types[j] + "o",
value: m[j][i]
});
}
}

const eigs = math.eigs(m);
eigs.vectors = math.transpose(eigs.vectors);
if (eigs.vectors[1][0] < 0) {
eigs.vectors[1][0] *= -1;
eigs.vectors[1][1] *= -1;
}

return Object.assign({ mat: m, inv: math.inv(m), displayMatrix }, eigs);
}
Insert cell
mat = {
button;
const m = mkMat();
return m;
}
Insert cell
parsedMats = {
const a = mats.map(({ mat }) => {
return toggleTranspose ? math.transpose(mat)[0] : mat[0];
});

const b = mats.map(({ mat }) => {
return toggleTranspose ? math.transpose(mat)[1] : mat[1];
});

const data = [];

a.map((d, idx) => {
data.push({ A: d[0], B: d[1], Type: "A", idx });
});
b.map((d, idx) => {
data.push({ A: d[0], B: d[1], Type: "B", idx });
});

return data;
}
Insert cell
parsedMats
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
mats = {
button;
const repeat = 100;
const ms = [];
for (let i = 0; i < repeat; ++i) {
ms.push(mkMat());
}
return ms;
}
Insert cell
/**
* Generate useable mat
* Generate the 2 x 2 matrix given one eigenvector and value.
* The other eigenvector and value is randomly matched to make sure
* the output matrix has positive values.
*/

mkMat = () => {
const c = Math.sqrt(Ipt.ResourceA ** 2 + Ipt.ResourceB ** 2);

const vectors = [
[-math.random(0.2, 0.8), Ipt.ResourceA / c],
[math.random(0.2, 0.8), Ipt.ResourceB / c]
];

const values = [
[(1 / Ipt.GrowthRate) * math.random(0.2, 0.8), 0],
[0, 1 / Ipt.GrowthRate]
];

const inv = math.inv(vectors);

const mat = math.multiply(math.multiply(vectors, values), inv);

const mul = math.multiply(vectors, math.transpose(vectors));

return { vectors, inv, mul, mat };
}
Insert cell
math = require("https://cdnjs.cloudflare.com/ajax/libs/mathjs/11.5.0/math.js")
Insert cell
schemes.multiHue
Insert cell
schemes = ({
categorical: [
"accent",
"category10",
"dark2",
"paired",
"pastel1",
"pastel2",
"set1",
"set2",
"set3",
"tableau10"
],
diverging: [
"brbg",
"prgn",
"piyg",
"puor",
"rdbu",
"rdgy",
"rdylbu",
"rdylgn",
"spectral"
],
reversedDiverging: ["burd", "buylrd"],
singleHue: ["blues", "greens", "greys", "oranges", "purples", "reds"],
multiHue: [
"turbo",
"viridis",
"magma",
"inferno",
"plasma",
"cividis",
"cubehelix",
"warm",
"cool",
"bugn",
"bupu",
"gnbu",
"orrd",
"pubu",
"pubugn",
"purd",
"rdpu",
"ylgn",
"ylgnbu",
"ylorbr",
"ylorrd"
],
cyclical: ["rainbow", "sinebow"]
})
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more