Qu

pwl

Builtin index · Plotting

pwl(x, y, [n_segments])

Input: x, y, n_segments · Output: no output

What it is

Continuous piecewise-linear least-squares fit through equal-length numeric Vecs x, y. n_segments (integer, positional, default 4) sets how many straight segments approximate the data; plotted through its own fitted breakpoints.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
pwl(x, y, [n_segments])
x VecContinuous piecewise-linear least-squares fit through equal-length numeric Vecs x, y.
y VecContinuous piecewise-linear least-squares fit through equal-length numeric Vecs x, y.
n_segments optionaln_segments (integer, positional, default 4) sets how many straight segments approximate the data.
no output—

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

figure()
splineplot([0, 1, 2, 3, 4], [0, 2, 1, 3, 2])
figure()
pwl([0, 1, 2, 3, 4, 5, 6], [0, 1, 1.5, 3, 3.2, 3.5, 5])
figure()
spiderplot([3, 4, 2, 5, 4])
figure()
raincloud(randn(60, seed = 6), randn(60, seed = 7))
-4 -3 -2 -1 0 1 2 3 4 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6

from plotting

How it works

pwl(x, y, [n_segments]) -- continuous piecewise-linear least-squares fit (default 4 segments), plotted directly as the polyline through its own breakpoints (see pwl_fit).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.