Skip to content

Fit

Performs a least-squares fit of data to a linear combination of basis functions.

$ wo 'Fit[{2, 4, 6}, {x}, x]'
2\.(0+\d*)?\*x (regex)

When the design matrix does not have full column rank there is no unique least-squares solution, and the minimum-norm one is returned. Fitting a line through a single point gives the shortest coefficient vector among the infinitely many lines through it:

$ wo 'Fit[{{1, 1}}, {1, x}, x]'
0\.(5(0+\d*)?|4999999999\d*) \+ 0\.(5(0+\d*)?|4999999999\d*)\*x (regex)

Repeated abscissae are the same situation — the fit passes through their mean:

$ wo 'Fit[{{1, 1}, {1, 2}}, {1, x}, x]'
0\.75(0+\d*)? \+ 0\.7(5(0+\d*)?|4999999999\d*)\*x (regex)
$ wo 'Fit[{{1, 1}, {1, 2}, {1, 3}}, {1, x}, x]'
1\.(0+\d*)? \+ 1\.(0+\d*)?\*x (regex)