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

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