Public
Edited
Dec 30, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// A list of students and their assigned functions.
// Often, I prepare this externally using Sympy.

names_and_functions = [
{ f: "", name: "" },
{
f: "x^3+6 x^2+9 x-1",
name: "Adrienne"
},
{
f: "x^3+5 x^2+6 x-1",
name: "Audrey"
},
{
f: "x^3+x^2-2 x-1",
name: "Flippy (anonymous student)"
},
{
f: "x^3+4 x^2+3 x-1",
name: "Mark"
}
]
Insert cell
Insert cell
// Define f
f = (x) => x ** 3 + x ** 2 - 2 * x - 1
Insert cell
// Take a look at a graph
funplot(f, { xdomain: [-3, 2], ydomain: [-8, 8] })
Insert cell
{
// Define the Newton's method iteration function N
let N = (x) => x - f(x) / (3 * x ** 2 + 2 * x - 2);

// Initialize x=1, since the root is nearby
let x = 1;

// Set up a list of points
let pts = [x];

// Iterate N!
// Note that we push each iterate onto the list of points
for (let i = 0; i < 6; i++) {
x = N(x);
pts.push(x);
}

// Return the pts
return pts;
}
Insert cell
Insert cell
import { funplot } from "@d3/funplot"
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