Published
Edited
Jul 9, 2018
Insert cell
Insert cell
Insert cell
class Derivative
{
constructor(f, epsilon = 0.01)
{
this.function = f;
this.epsilon = epsilon;
}
gradient(x0)
{
throw new Error("Need an implementation");
}
}
Insert cell
Insert cell
Insert cell
Insert cell
class SimpleDerivative extends Derivative
{
constructor(f, epsilon)
{
super(f, epsilon);
}
gradient(x0)
{
return (this.function(x0 + this.epsilon) - this.function(x0)) / this.epsilon;
}
}
Insert cell
Insert cell
Insert cell
class SymmetricDerivative extends Derivative
{
constructor(f, epsilon)
{
super(f, epsilon);
}
gradient(x0)
{
return (this.function(x0 + this.epsilon) - this.function(x0 - this.epsilon)) / (2*this.epsilon);
}
}
Insert cell
Insert cell
class FivePointStencil extends Derivative
{
constructor(f, epsilon)
{
super(f, epsilon);
}
gradient(x0)
{
let numerator = -this.function(x0 + 2 * this.epsilon) + 8 * this.function(x0 + this.epsilon) - 8 * this.functionf(x0 - this.epsilon) + this.function(x0 - 2* this.epsilon)
return numerator / (12 * this.epsilon);
}
}
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