PhDino scholar
Numerical Lab: Integrate, Differentiate, Solve ODEs

Numerical Lab: Integrate, Differentiate, Solve ODEs

Three classic numerical methods, each laying out its working the way a lecturer would on the board. Integrate approximates the area under a curve with Simpson's rule, which fits a parabola through each pair of strips; its table lists every point, its weight and the sum. Differentiate estimates the slope at a point from the function's values just either side of it, a central difference, and the second derivative from the same three values. Solve an ODE steps y′ = f(x, y) forward with the classical fourth-order Runge–Kutta method and tabulates the four slopes of every step.

Each answer is checked by running again with half the step: the change between the two runs estimates the error, and combining the pair (Richardson extrapolation) is usually closer still.

∫ from to ofdx, n = intervals
012300.51
∫ ≈ 2.000269 Simpson's rule, n = 8
The working

Step h = (b − a) / n = (3.141593 − 0) / 8 = 0.3926991. Simpson's rule fits a parabola through each pair of strips, which weights the points 1, 4, 2, 4, …, 2, 4, 1:

ixᵢf(xᵢ)weightweight × f(xᵢ)
00010
10.39269910.382683441.530734
20.78539820.707106821.414214
31.1780970.923879543.695518
41.570796122
51.9634950.923879543.695518
62.3561940.707106821.414214
72.7488940.382683441.530734
83.1415931.224647e-1611.224647e-16

Sum = 15.28093, and h / 3 × sum = 0.1308997 × 15.28093 = 2.000269.

Check: with n = 16 the rule gives 2.000017. Its error shrinks about 16× each time the step halves, so that answer is off by about |2.000017 − 2.000269| / 15 = 0.000016839, and 2.000017 + (2.000017 − 2.000269) / 15 = 2 is closer still (Richardson extrapolation).

Type a function of x with + − * / ^ and brackets; 2x means 2 × x. Also pi, e and sin cos tan asin acos atan sinh cosh tanh sqrt abs exp ln log floor ceil (angles in radians; log is base 10, ln natural). Number fields take pi/2 too.

The other accessories

  • Constants: Physical constants: the CODATA 2022 values from NIST
  • Units: Convert a value between units
  • Plot: Graph a function of x