Public
Edited
Jan 19, 2023
Fork of mat
Insert cell
Insert cell
m.evaluate(`t = 0:10;
y = sin(t)`).toString()
Insert cell
math.format(
m.evaluate(`x = 1:10;
xsums = cumsum(x);
y = xsums[5:5:end]`), 4)
Insert cell
math.format(
m.evaluate(`D=1:10;
H= 11:20;
V= 1/12*pi*(D.^2).*H`), 4)
Insert cell
math.format(
m.evaluate(`A = [97, 89, 84; 95, 82, 92; 64, 80, 99;76, 77, 67; 88, 59, 74; 78, 66, 87; 55, 93, 85];
devA = A - mean(A)`), 4)
Insert cell
Insert cell
math.format(
m.evaluate(`x = (-2:0.2:2)'; # 21-by-1
y = -1.5:0.2:1.5; # 1-by-16
#size(x+y)
#F = x.*exp(-(x+0*y).^2-(y+0*x).^2); # 21-by-16`), 4)
Insert cell
math.index([true],1)
Insert cell
toVectotize = [
'exp(1:10)',
'log(1:10)',
'log(1:10,2)',
'gamma(1:10)',
'square(1:10)',
'cube(1:10)',
'cbrt(1)',
'cbrt(1:10)',
'acos(1:10)',
'acosh(1:10)',
'acot(1:10)',
'acoth(1:10)',
'acsc(1:10)',
'acsch(1:10)',
'asec(1:10)',
'asech(1:10)',
'asin(1:10)',
'asinh(1:10)',
'atan(1:10)',
'atan2(1:10, 1:10)',
'atanh(1:10)',
'cos(1:10)',
'cosh(1:10)',
'cot(1:10)',
'coth(1:10)',
'csc(1:10)',
'csch(1:10)',
'sec(1:10)',
'sech(1:10)',
'sin(1:10)',
'sinh(1:10)',
'tan(1:10)',
'tanh(1:10)'
]
Insert cell
toVectotize.map(e=> m.evaluate(e)) //.entries.map(e => math.format(e,6)).join('\n')
Insert cell
m.evaluate('atan2(1:10, 1:10)')
Insert cell
mat.evaluate('A = [1]; A[1]')
Insert cell
function mapped(f, x) {
return math.sum(math.size(x)) > 0 ? math.map(x, f) : f(x)
}
Insert cell
Insert cell
math.format(
math.evaluate('map([1, 8, 27], _(x)=cbrt(x))')
)
Insert cell
// this is for the functions that do not work with map
// no longer needed
/*
function mappedF(f, x) {
return math.sum(math.size(x)) > 0 ? math.matrix(x.toArray().map(x=>f(x))) : f(x)
}
*/
Insert cell
math.matrix([1])
Insert cell
function mapLog(x, ...args) {
const base = args.length == 0 ? math.e : args[0]
return math.sum(math.size(x)) > 0 ? math.map(x, x => math.log(x, base)) : math.log(x, base)
}
Insert cell
math.index(1)
Insert cell
mat.index(0)
Insert cell
mat.evaluate('A=[1]; A[1]')
Insert cell
mat = math.create(math.all)
Insert cell
mat.import({
//index: (...args) => math.index(...args),
index: math.index,
exp: x => mapped(math.exp, x),
log: mapLog,
gamma: x=> mapped(math.gamma, x),
square: x=> mapped(math.square, x),
sin: x => mapped(math.sin, x),
cos: x => mapped(math.cos, x),
cube: x => mapped(math.cube, x),
//cbrt: x => mapped(math.cbrt, x),
cbrt: x => mapped(x2 => math.cbrt(x2), x), // this is a temporary fix as cbrt doesn't work with map
acos: x => mapped(math.acos, x),
acosh: x => mapped(math.acosh, x),
acot: x => mapped(math.acot, x),
acoth: x => mapped(math.acoth, x),
acsc: x => mapped(math.acsc, x),
acsch: x => mapped(math.acsch, x),
asec: x => mapped(math.asec, x),
asech: x => mapped(math.asech, x),
asin: x => mapped(math.asin, x),
asinh: x => mapped(math.asinh, x),
atan: x => mapped(math.atan, x),
atanh: x => mapped(math.atanh, x),
cosh: x => mapped(math.cosh, x),
cot: x => mapped(math.cot, x),
coth: x => mapped(math.coth, x),
csc: x => mapped(math.csc, x),
csch: x => mapped(math.csch, x),
sec: x => mapped(math.sec, x),
//'atan2(1:10, 1:10)', already works it hasn't lost it's vectorization
sech: x => mapped(math.sech, x),
sin: x => mapped(math.sin, x),
sinh: x => mapped(math.sinh, x),
tan: x => mapped(math.tan, x),
tanh: x => mapped(math.tanh, x),
},{override:true})
Insert cell
m = mat.parser()
Insert cell
math = require("mathjs")
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