### 7.2.8 Polynomial regression: polynomial_regression polynomial_regression_plot

If you want to find a more general polynomial y=a_{0}x^{n} + … + a_{n}
which best fits a set of data points, you can use the
polynomial_regression command.
Given a set of points, either as a list of x-coordinates
followed by a list of y-coordinates, or simply by a list of points,
as well as a power n, the polynomial_regression command
will return the list [a_{n},…,a_{0}] of coefficients of the
polynomial. For example, if you enter

polynomial_regression([[1,1],[2,2],[3,10],[4,20]],3)

or

polynomial_regression([1,2,3,4],[1,2,10,20],3)

you will get

[-5/6,17/2,-56/3,12]

so the best fit polynomial will be y = (−5/6)x^{3} + (17/2)x^{2} −
(56/3)x + 12.

To plot the curve, you can use the command
polynomial_regression_plot; if you enter

polynomial_regression_plot([1,2,3,4],[1,2,10,20],3)

you will get