Public
Edited
Aug 3, 2023
Insert cell
Insert cell
Insert cell
Insert cell
function factorial(x) {
return !x ? 1 : x * factorial(x - 1);
}
Insert cell
expTerm = (x, n) => (x ** n) / factorial(n)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function series(term) {
return function* (x) {
let collector = 0, n = 0, t;
while (!isNaN(t = term(x, n++))) {
yield collector += t;
if (Math.abs(t) < 1e-9) break;
}
};
}
Insert cell
exp = series(expTerm)
Insert cell
Insert cell
Insert cell
ex = exp(expX)
Insert cell
Insert cell
Math.exp(expX)
Insert cell
Insert cell
Insert cell
Insert cell
cosTerm = (x, n) => (n % 2 ? -1 : 1) * expTerm(x, n * 2)
Insert cell
cos = series(cosTerm)
Insert cell
Insert cell
sinTerm = (x, n) => (n % 2 ? -1 : 1) * expTerm(x, n * 2 + 1)
Insert cell
sin = series(sinTerm)
Insert cell
Insert cell
function* expI(x) {
let _r = cos(x), r;
let _i = sin(x), i;
while (!(r = _r.next()).done && !(i = _i.next()).done) {
yield [r.value, i.value];
}
}
Insert cell
Insert cell
Insert cell
ex2 = expI(expX)
Insert cell
Insert cell
round = (x, place) => Math.round(x * 10 ** place) / 10 ** place
Insert cell
formatComplex = ([r, i]) => {
r = round(r, 6);
i = round(i, 6);
return tex`
${r ? r : ""}
${r && i ? (i > 0 ? "+" : "-") : ""}
${i ? `i${Math.abs(i) !== 1 ? Math.abs(i) : ""}` : ""}`;
}
Insert cell
formatComplex(ex2)
Insert cell
Insert cell
expI1 = (x) => formatComplex([Math.cos(x), Math.sin(x)])
Insert cell
Insert cell
Insert cell
expI1(expX)
Insert cell
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