This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Numerics

Floating point

demoAINumericswritten with an agent#5589c09a31

Three floating-point failures in summation, cancellation and RANDU

Adding for up to a million left to right ends 414 units in the last place (ulps) from the correctly rounded sum; Kahan's compensated sum is correctly rounded at all 31 checkpoints from 1 to . Evaluating from its expanded coefficients near gives rounding noise: 89 sign changes among 401 points, where the polynomial has one, and 8.5 times the true value at . The factored form is within everywhere. The random number generator RANDU puts every triple of successive draws on one of 15 planes.

Sum of 1/k, k = 1 .. N: error in ulps of the exact sum
left to rightKahan
−400−200010⁰10¹10²10³10⁴10⁵10⁶Ncomputed - correctly rounded (ulps)
$(x - 1)^7$: factored, and expanded by Horner's rule
0.98 to 1.02
Horner, expanded(x−1)7, factored
-1e-1201e-120.980.991.001.011.02xp(x)
0.995 to 1.005
Horner, expanded(x−1)7, factored
-5e-1505e-150.9960.9981.0001.0021.004xp(x)
$9u_k - 6u_{k+1} + u_{k+2}$ against $u_k$, 600 triples
RANDU-5051000.20.40.60.81uk9uk−6uk+1+uk+2
RANDU
MINSTD-5051000.20.40.60.81uk9uk−6uk+1+uk+2
MINSTD
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Integrating in time

demoAINumericswritten with an agent#70ee9cc956

Forward Euler loses the planet

Ten orbits of a planet on an ellipse, 200 steps an orbit, stepped two ways at the same cost. Forward Euler gains energy until the planet is unbound. Leapfrog's energy error stays under one percent, and it keeps the angular momentum to rounding.

Energy error over ten orbits, equal step size
forward Eulerleapfrog
−4−3−2−10246810orbitslog10 of the energy error
✓ 7 tests passchecked when the site was built#orbits#integrators
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

demoAINumericswritten with an agent#82acda210a

Forward and backward Euler on either side of h = 2/λ

The exact solution of this equation is , which a step of 0.1 would follow to a few digits. With , forward Euler is within of it at with , and off by at . A disturbance is multiplied by each step, and the measured factor matches to at 36 step sizes. Backward Euler's factor is , below 1 at every step size, and at it is still within of .

y' = -1000 (y - cos t) - sin t, from y(0) = 1-10100.511.52ty
cos t, exactforward Euler, h = 0.0019forward Euler, h = 0.0021backward Euler, h = 0.01
Growth factor per step, measured and predicted (λ=1000)10⁻²10⁰10²10⁻⁴10⁻³10⁻²10⁻¹step h|g|
|1−hλ|1/(1+hλ)forward Euler, measuredbackward Euler, measured
✓ 9 tests passchecked when the site was built#ode#stiffness#forward-euler#backward-euler#stability#notebook
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

problemAINumericswritten with an agent#e6f3a56fdf

Make Euler stable on a stiff equation

The solution of decays to zero, but forward Euler with step multiplies by every step, and after 12 steps it is 129.7 instead of . Rewrite decay_step and system_step as backward Euler, which takes the slope at the end of the step instead of the start, so that no step size makes them grow.

  • one step of 0.05 multiplies y by 1 / (1 + 2.5) = 0.285714
  • twelve steps of 0.05 leave 2.9593e-7: small and positive, never negative
  • a step 25 times the forward-Euler limit, h = 1, gives 1/51 = 0.0196
  • ten steps of 0.1 on the system end at numpy's (0.38554, 0.38554): the fast mode is gone
✗ 4 tests to solvethe unfinished functions run, and the failing tests show what they must computeno solutions yet#ode#stiffness#implicit-methods#backward-euler#problem
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

problemAINumericswritten with an agent#dfc71ed5d9

Make Numerov find the decaying solution

Numerov's method integrates outward from , , aiming at the decaying solution . By it is off by a factor of 30, and by by . Rewrite decaying so that it follows to Numerov's own accuracy, within , on both intervals.

  • with h = 0.15 on [0, 9] every point is within 1.3e-5 of e^(-x), where numpy's inward run reaches 8.87e-6
  • with h = 0.075 on [0, 9] every point is within 8e-7, where numpy reaches 5.58e-7
  • with h = 0.15 on [0, 18], where outward is off by 2e9, every point is within 2.7e-5 (numpy reaches 1.84e-5)
  • y(0) = 1
  • halving h divides the error by 12 to 20, as a fourth-order method's should (numpy: 15.9)
✗ 3 tests to solve2 pass already · the unfinished functions run, and the failing tests show what they must computeno solutions yet#ode#numerov#shooting#stability#problem
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Approximation

articleAINumericswritten with an agent#b93d4ae27a
Adam Zettel@adam1 min read

The Runge phenomenon, where more points give a worse fit

Interpolate by a polynomial through equally spaced points and the error grows as you add points. Move the same number of points to and it falls geometrically, at a rate you can work out from where the function's poles are.

Interpolating 1/(1+25x2) at 21 points
1/(1+25x2)equally spacedChebyshev
00.51.0−1.0−0.500.51.0xinterpolant

1 paragraph · 4 functions · 1 min

✓ 3 tests passchecked when the site was built#interpolation#approximation

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

articleAINumericswritten with an agent#a67916e929
Adam Zettel@adam2 min read

The Gibbs overshoot never shrinks

Add more terms to the Fourier series of a square wave and the wiggle at the jump gets narrower, never shorter. It overshoots by 8.95% of the jump however many terms you take, and the number comes from an integral.

Square wave at the jump, partial sums m = 5 to 80
0.81.01.200.20.40.60.81.0xpartial sum

 

0.0 / 12.5 s

8 paragraphs · 3 functions · 2 min

✓ 4 tests passchecked when the site was built#fourier#analysis

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Quadrature

demoAINumericswritten with an agent#0b475cd75c

Gauss-Legendre quadrature against tanh-sinh on a smooth and a singular integral

Five Gauss-Legendre points integrate every polynomial of degree 9 or less exactly, and miss degree 10 by exactly what the error formula says. On seven points reach rounding. On , which is infinite at both ends of the interval, 128 points still miss by , and the error only halves when the points double. The tanh-sinh rule gets that integral to rounding with 37 points.

Relative error on the integral of (1+x)k
5 points3 points
10⁻¹⁶10⁻¹²10⁻⁸10⁻⁴10⁰024681012degree krelative error
1/1−x2 on [−1,1]: error against points10⁻¹⁵10⁻¹⁰10⁻⁵10⁰10¹10²points|error|
Gauss-Legendretanh-sinh
ex on [−1,1]: error against points10⁻¹⁵10⁻¹⁰10⁻⁵10⁰10⁰10¹10²points|error|
Gauss-Legendretanh-sinh
✓ 13 tests passchecked when the site was built#quadrature#integration#gauss-legendre#tanh-sinh#notebook
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Eigenvalues

demoAINumericswritten with an agent#8b2f1cac21

How far a finite-difference Hamiltonian's levels sit below n + 1/2

Put on a grid and diagonalize: the levels come out at , a little low. How low is predictable. First-order perturbation theory gives , and for the six lowest levels the measured shift matches it to within half a percent (the test allows 4%).

The three lowest eigenfunctions
n=0n=1n=2
−0.500.5−6−4−20246xψ
✓ 3 tests passchecked when the site was built#quantum#eigenvalues
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

demoAINumericswritten with an agent#fd96a8df95

The eigenvalues of a random matrix fill Wigner's semicircle

Fill a symmetric matrix with independent random numbers, divide by , and look at its eigenvalues. They do not scatter. They fill the semicircle , whatever distribution the entries came from.

Eigenvalues of one N x N random symmetric matrix
histogramsemicircle
00.10.20.3−2−1012eigenvaluedensity
✓ 4 tests passchecked when the site was built#random-matrices#statistics
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

articleAINumericswritten with an agent#e20fe3d0a4
Adam Zettel@adam5 min read

LOBPCG finds the lowest states of a particle in a box

The six lowest states of a particle in a square box, from random starting vectors, in 103 steps of LOBPCG, and the 576 by 576 Hamiltonian is never written down. Each step searches three blocks of vectors: the current guesses, their residuals, and the step each guess took last time. Leave out the third block and the same run takes 797 steps.

Residual norm of each state, per LOBPCG step
(1,1)(1,2)(2,1)(2,2)(1,3)(3,1)tolerance
−10−50020406080100steplog10∥Hx−λx∥
The worst wanted residual, with and without the previous step p
LOBPCG: x, w and p (held at its last value once done)steepest descent: x and w
−500200400600steplog10 residual norm
The six lowest states
(1,1)
24 × 24 grid
the (1,2) and (2,1) pair
24 × 24 grid
the (1,2) and (2,1) pair
24 × 24 grid
(2,2)
24 × 24 grid
the (1,3) and (3,1) pair
24 × 24 grid
the (1,3) and (3,1) pair
24 × 24 grid

26 paragraphs · 28 functions · 5 min

✓ 6 tests passchecked when the site was built#eigenvalues#linear-algebra#quantum

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

demoAINumericswritten with an agent#295447f910

Jacobi's eigenvalue method

Jacobi's method diagonalizes a symmetric matrix by plane rotations, each of which zeroes one off-diagonal pair. On an 8 by 8 matrix the off-diagonal norm goes 1.33, 0.453, 0.0299, , over four sweeps, and after the fifth it is under , rounding error. The diagonal is then the spectrum, and it matches numpy.linalg.eigh to .

Off-diagonal norm after each Jacobi sweep, 8 by 8 matrix
off(A)
10⁻¹⁶10⁻¹²10⁻⁸10⁻⁴10⁰0123456sweepoff(A)
✓ 10 tests passchecked when the site was built#eigenvalues#linear-algebra#jacobi#convergence#notebook
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

problemAINumericswritten with an agent#9fbf3ac156

Make power iteration converge on a tied pair

Power iteration multiplies a vector by again and again and finds the eigenvalue of largest magnitude. The matrix above has two, and , of the same magnitude, and the iterate swaps its two entries every step forever. Write shifted_power so that the shift breaks the tie: iterate with , whose eigenvalues are .

  • shift +1 finds eigenvalue 2, vector (1, 1) / sqrt 2
  • shift -1 finds eigenvalue -2, vector (1, -1) / sqrt 2
  • on [[1, 2], [2, -1]] shift +1 finds sqrt 5 = 2.2360680 with numpy's vector
  • and shift -1 finds -sqrt 5
✗ 4 tests to solvethe unfinished functions run, and the failing tests show what they must computeno solutions yet#eigenvalues#power-iteration#shifts#linear-algebra#problem
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

demoAINumericswritten with an agent#d003d94d29

Lanczos finds the largest eigenvalue three times

Sixty steps of Lanczos on a 200 by 200 symmetric matrix whose eigenvalues are known exactly. Both ends of the spectrum, , come out right to . But in floating point the basis stops being orthogonal once the top eigenvalue has converged, the direction of its eigenvector creeps back in, and the eigenvalue 4, which the matrix has once, is found again and again. Orthogonalizing each new vector against all the old ones stops it.

Plain Lanczos against full reorthogonalization, step by step
Component of the new basis vector along the eigenvector for 4
plain three-term recurrencefull reorthogonalization
10⁻¹⁵10⁻¹⁰10⁻⁵10⁰|qj⋅u|
Largest overlap of the new basis vector with an earlier one
plain three-term recurrencefull reorthogonalization
10⁻¹⁶10⁻¹²10⁻⁸10⁻⁴10⁰01020304050Lanczos step jmax|qj⋅qi|, i<j
The three largest Ritz values
plain, largestplain, 2ndplain, 3rdreorthogonalized, largestreorthogonalized, 2ndreorthogonalized, 3rd
123401020304050Lanczos step jRitz value
✓ 12 tests passchecked when the site was built#eigenvalues#linear-algebra#lanczos#krylov#rounding#notebook
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Orthogonalization

problemAINumericswritten with an agent#386cd64c28

Make Gram-Schmidt orthogonal to rounding

Ten nearly parallel vectors, each plus a tiny in its own direction. Classical Gram-Schmidt turns them into ten "orthonormal" vectors of which two are at 60 degrees: their dot product is 0.5. Rewrite orthonormalize so the vectors it returns are orthogonal to and equal the exact ones to .

  • the rows are orthonormal to 1e-15 (classical Gram-Schmidt gives 0.5, modified 7.1e-9)
  • the second vector is mpmath's (7.07e-9, -1/sqrt 2, 1/sqrt 2, 0, ...)
  • the last vector is mpmath's (1.05e-9, -0.10541 nine times, 0.94868)
  • each input row is rebuilt from the rows before it: a_k = sum over j <= k of (q_j . a_k) q_j
✗ 4 tests to solvethe unfinished functions run, and the failing tests show what they must computeno solutions yet#linear-algebra#gram-schmidt#orthogonalization#rounding#problem
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Partial differential equations

problemAINumericswritten with an agent#e1e71349a4

Make the heat-equation step stable past r = 1/2

The explicit (FTCS) step for multiplies the grid's most jagged mode by about each step, and for that is : a checkerboard that should fade grows to 215 in 16 steps. Rewrite heat_step as backward Euler, which needs a tridiagonal solve per step and damps every mode for every .

  • the smoothest mode decays by 1 / (1 + 2.4 sin^2(pi/40))^16 = 0.790844 at r = 0.6
  • the most jagged mode, m = 19, decays to 3.362e-9 of itself instead of growing
  • the checkerboard at r = 0.6 fades to numpy's 0.0068342 after 16 steps
  • and at r = 5, ten times the FTCS limit, to numpy's 0.0012278
  • the ends stay at 0
✗ 4 tests to solve1 pass already · the unfinished functions run, and the failing tests show what they must computeno solutions yet#pde#heat-equation#stability#implicit-methods#problem
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Matrix equations

demoAINumericswritten with an agent#f45cc94837

The error of a linear solve follows the condition number

Gaussian elimination with partial pivoting solves Hilbert systems whose exact solution is all ones. From to 12 the condition number grows from 524 to , and the error grows with it, staying between 0.005 and 0.18 times , while the residual stays under . In least squares, fitting a degree-11 polynomial to 40 points, Householder QR is off by (about ), and the normal equations, which square , by 0.18.

Hilbert systems, n=3 to 12: error against κ10⁻¹⁵10⁻¹⁰10⁻⁵10⁰10⁴10⁸10¹²10¹⁶condition number κmax |x - 1|
κϵGEPP errorresidual / (|A| |x|)
Fitting degree 3 to 13 at 40 points: coefficient error against κ(V)10⁻¹⁵10⁻¹⁰10⁻⁵10⁰10²10⁴10⁶10⁸10¹⁰condition number of Vmax |c - 1|
κϵκ2ϵHouseholder QRnormal equations
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

demoAINumericswritten with an agent#cec2f50a64

Jacobi, SOR and conjugate gradients on the Poisson equation

The five-point Poisson equation on a 15 by 15 grid, solved to a relative residual of four ways. Jacobi takes 948 sweeps, Gauss-Seidel 475, SOR with the optimal factor 60, and conjugate gradients 25 iterations. Each count follows from one number the theory predicts: Jacobi's error shrinks by per sweep once the smoothest mode dominates, Gauss-Seidel's by its square, and SOR and CG depend on . Halve and Jacobi takes four times as many sweeps; SOR and CG take twice as many.

Relative residual, 15 by 15 grid10⁻⁹10⁻⁶10⁻³10⁰0200400600800iteration|b - A u| / |b|
Jacobi10cos(πh)k, a decade upGauss-Seidel10cos2(πh)k, a decade upSORCG
Iterations to a residual of 1e-8 against grid size
JacobiJacobi, lntol/lncos(πh)SORSOR, lntol/ln(ω−1)CGCG, κ
10²10³20301/hiterations
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

demoAINumericswritten with an agent#7e2c4a61ad

Solving the Riccati equation without integrating it

Every LQR controller comes from a quadratic matrix equation, and the tempting way to solve it is to integrate the differential version backwards until it stops moving. On a one-state system that method returns 73.783 where the answer is 414.214, with no warning. The Schur method Laub published in 1979 returns the answer to rounding error, and this post runs it.

The Hamiltonian's twelve eigenvalues-0.500.5-2-1012real partimaginary part
the six stable ones, which P is built fromthe six unstable ones, discarded
Each subdiagonal entry shrinking to zero
entry 9, the first to goentry 7, which goes nextentry 3, higher up
10⁻²⁸10⁻²¹10⁻¹⁴10⁻⁷10⁰051015202530turns of the outer loopthe entry's size
The subdiagonal being driven to zero
−15−10−500246810which subdiagonal entrylog10 of its size

 

0.0 / 9.9 s
Relative residual, ten systems, two methods
the Schur methodthe matrix sign function
−16−14−1202468systemlog10 of the relative residual
✓ 10 tests passchecked when the site was built#control#linear-algebra#schur#riccati
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

PDEs

demoAINumericswritten with an agent#a4811d5668

Upwind advection smears the pulse by its modified equation

First-order upwind carries a Gaussian pulse once around a periodic domain at Courant number . The mass is kept to rounding and no new maximum or minimum appears, but the peak falls from 0.9975 to 0.5767. The scheme's modified equation adds a diffusion term with , which predicts the fall to and predicts the pulse's variance growth, , exactly.

One transit of upwind at ν=0.5, N=200
start, and the exact answer after one transitupwind after 400 stepsthe modified equation's Gaussian
00.51.000.20.40.60.81.0xu
Upwind after one transit, against its modified equation
Peak height
1/5−4νupwind
0.60.81.00.20.40.60.81.0Courant number νpeak
Variance growth
2DT=(1−ν)hupwind, measured
00.0010.0020.0030.0040.20.40.60.81.0Courant number νvariance growth
✓ 10 tests passchecked when the site was built#pde#advection#upwind#numerical-diffusion#modified-equation#notebook
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

demoAINumericswritten with an agent#9458e4aca8

Crank-Nicolson is second order in time, backward Euler first

The heat equation from , stepped to with six time steps from 0.02 down to 0.000625. Each halving cuts the Crank-Nicolson error by a factor of 4.0 to 4.7 (measured order 2.09 to 2.23, then 2.000) and the backward Euler error by 1.9 to 2.0 (order 0.94 to 0.996). The errors are measured against the exact solution of the space-discretized equation, a discrete sine series. Against the exact Fourier series of the PDE, the Crank-Nicolson error stops falling at the space error, .

Error at t = 0.1 against the time step
backward Eulerslope 1Crank-Nicolsonslope 2Crank-Nicolson against the PDE series
10⁻⁶10⁻⁴10⁻²10⁻³10⁻²dtmax errorspace error 1.95e-6
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

demoAINumericswritten with an agent#7389123e4c

Burgers' equation in nonconservative form puts the shock in the wrong place

For smooth solutions, and are the same equation. For a shock from to they are not. A scheme built on the first form, Godunov's, moves the shock at 0.625, the Rankine-Hugoniot speed , to rounding. Upwinding the second form moves it at 0.5132, on 400, 800 and 1600 cells alike, so refining the grid does not fix it. With the nonconservative shock stays at , with speed 0.

Burgers, uL=1, uR=0.25, at t=1 (800 cells)
start, t = 0exact: shock at x = 0.625conservative (Godunov)nonconservative (uux upwinded)
00.51.0−0.500.51.01.5xu
Shock position from the mass (uR=0.25)
Rankine-Hugoniot, x = 0.625 tconservativenonconservative
00.20.40.600.20.40.60.81.0txs
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Roots

demoAINumericswritten with an agent#cd6c853aa2

Which root does Newton's method find?

Solve by Newton's method from every point of a square and color each start by the root it reaches. Near a root the answer is obvious. Along the lines between them it is a fractal: every boundary point touches all three basins.

Basins of the three cube roots of 1
Im z
Re z
128 × 128 grid
✓ 3 tests passchecked when the site was built#fractals#root-finding
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Also in Numerics

articleAINumericswritten with an agent#1173edd4ea
Adam Zettel@adam2 min read

Finite differences and spectral methods

Two ways to differentiate a function you only know at grid points. A central difference uses the two neighbors; a spectral derivative uses every point. On a smooth periodic function the spectral one reaches rounding error with a few dozen points. Put a jump in the function and, away from the jump, the central difference is the accurate one.

Largest derivative error against the number of points
spectral, exp(sin x)central difference, exp(sin x)spectral, sin x + step, far pointscentral difference, sin x + step, far points
10⁻¹²10⁻⁹10⁻⁶10⁻³10⁰10¹10²Nlargest error

10 paragraphs · 8 functions · 2 min

✓ 3 tests passchecked when the site was built#numerics#fourier#derivatives

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

demoAINumericswritten with an agent#ca6b837769

Electron mobility fitted to NIST's certified digits

A seven-parameter rational model fitted to NIST's semiconductor electron-mobility data by lmder, the Levenberg-Marquardt routine of MINPACK, translated to Viv step by step. Every trial step matches a gfortran build of the original Fortran to the last bit, the answer matches scipy.optimize.leastsq, and the parameters land within 0.001 standard deviations of NIST's certified values.

NIST's electron mobility datawith the fitted rational model050010001500-3-2-1012x = ln(density)mobility
NIST's measurementsthe fitted rational model
Convergence, one point per trial step
How far the norm of the residuals is from its final value
norm of residuals - final norm
10⁻⁶10⁻³10⁰10³norm - final norm
The trust radius
trust radius δ
10¹10²10³10⁴51015202530trial stepδ
✓ 8 tests passchecked when the site was built#least-squares#levenberg-marquardt#minpack#curve-fitting#nist
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • Explore

    Run it and step through what each part did, with the code, values and plots beside it.

demoAINumericswritten with an agent#009c306ada

Newton's method doubles the correct digits

Newton's method on , one cell at a time. From the error is after four steps and zero after five; bisection needs 39 halvings to promise as much. Each Newton step squares the error, and a cell checks the constant in front.

Error after n steps, x2=2 from x0=110⁻¹²10⁻⁸10⁻⁴10⁰010203040step nerror
Newton, |xn−2|bisection, half the interval
✓ 7 tests passchecked when the site was built#newton#root-finding#convergence#notebook
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.