Published
Edited
Apr 13, 2020
Insert cell
Insert cell
Insert cell
Insert cell
class DualNumber {
constructor(real, nilCoef) {
this.real = real
this.nilCoef = nilCoef
}
add(otherDual) {
this.real += otherDual.real
this.nilCoef += otherDual.nilCoef
}
addReal(otherReal) {
this.real += otherReal
}
multiply(otherDual) {
// (a+a'd)*(b+b'd) = ab+(ab'+a'b)d
let newReal = this.real * otherDual.real
let newNilCoef = this.real * otherDual.nilCoef + otherDual.real * this.nilCoef
this.real = newReal
this.nilCoef = newNilCoef
}
}
Insert cell
class Polynomial {
constructor(coefficients) {
this.coefficients = coefficients
}
// Use Horner's method to calculate the value of the polynomial.
// https://en.wikipedia.org/wiki/Horner%27s_method
evaluate(input) {
var value = new DualNumber(this.coefficients[0], 0)
for (var i = 1, l = this.coefficients.length; i < l; i++) {
value.multiply(input)
value.addReal(this.coefficients[i])
}
return value
}
}
Insert cell
d3 = require('d3')
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