Bivariate Polynomial Regression - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Bivariate Polynomial Regression

This application:

 • Allows arbitrary 3-D data to be specified (for example, a table of X, Y, Z points).
 • Generates a bivariate polynomial with a customizable order.
 • Fits the polynomial to the data with a least-squares fit.
 • Plots the data against the best-fit polynomial surface.
 Specify the Data Set Below we include some sample point data in a DataTable component and associate it with the variable $\mathrm{data}$.     Alternatively, this data could be imported from an external source using the Import command.

Define Model Equation

The general form of a bivariate polynomial of total degree $n$ is given by:

$f:=n\to \sum _{j=0}^{n}\phantom{\rule[-0.0ex]{5.0px}{0.0ex}}\left(\sum _{i=0}^{n}\phantom{\rule[-0.0ex]{5.0px}{0.0ex}}{a}_{i,j}{x}^{i}{y}^{j}\right)$

 ${f}{≔}{n}{↦}{\sum }_{{j}{=}{0}}^{{n}}{}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{\sum }_{{i}{=}{0}}^{{n}}{}{{a}}_{{i}{,}{j}}{\cdot }{{x}}^{{i}}{\cdot }{{y}}^{{j}}$ (2.1)

For example, the general form for a bivariate quadratic is:

$f\left(2\right)$

 ${{a}}_{{2}{,}{2}}{}{{x}}^{{2}}{}{{y}}^{{2}}{+}{{a}}_{{2}{,}{1}}{}{{x}}^{{2}}{}{y}{+}{{a}}_{{1}{,}{2}}{}{x}{}{{y}}^{{2}}{+}{{a}}_{{2}{,}{0}}{}{{x}}^{{2}}{+}{{a}}_{{1}{,}{1}}{}{x}{}{y}{+}{{a}}_{{0}{,}{2}}{}{{y}}^{{2}}{+}{{a}}_{{1}{,}{0}}{}{x}{+}{{a}}_{{0}{,}{1}}{}{y}{+}{{a}}_{{0}{,}{0}}$ (2.2)

Next, we choose the order of the bivariate polynomial which we will fit to the points. Increasing this value will refine the fit.

 ${n}{≔}{3}$ (2.3)

 ${\mathrm{poly}}{≔}\left({x}{,}{y}\right){↦}{{x}}^{{3}}{\cdot }{{y}}^{{3}}{\cdot }{{a}}_{{3}{,}{3}}{+}{{x}}^{{3}}{\cdot }{{y}}^{{2}}{\cdot }{{a}}_{{3}{,}{2}}{+}{{x}}^{{2}}{\cdot }{{y}}^{{3}}{\cdot }{{a}}_{{2}{,}{3}}{+}{{x}}^{{3}}{\cdot }{y}{\cdot }{{a}}_{{3}{,}{1}}{+}{{x}}^{{2}}{\cdot }{{y}}^{{2}}{\cdot }{{a}}_{{2}{,}{2}}{+}{x}{\cdot }{{y}}^{{3}}{\cdot }{{a}}_{{1}{,}{3}}{+}{{x}}^{{3}}{\cdot }{{a}}_{{3}{,}{0}}{+}{{x}}^{{2}}{\cdot }{y}{\cdot }{{a}}_{{2}{,}{1}}{+}{x}{\cdot }{{y}}^{{2}}{\cdot }{{a}}_{{1}{,}{2}}{+}{{y}}^{{3}}{\cdot }{{a}}_{{0}{,}{3}}{+}{{x}}^{{2}}{\cdot }{{a}}_{{2}{,}{0}}{+}{x}{\cdot }{y}{\cdot }{{a}}_{{1}{,}{1}}{+}{{y}}^{{2}}{\cdot }{{a}}_{{0}{,}{2}}{+}{x}{\cdot }{{a}}_{{1}{,}{0}}{+}{y}{\cdot }{{a}}_{{0}{,}{1}}{+}{{a}}_{{0}{,}{0}}$ (2.4)

Calculate Parameters by Least Squares Minimization

Separate and normalize the data

$\mathrm{with}\left(\mathrm{LinearAlgebra}\right):$

 ${\mathrm{nRows}}{≔}{176}$ (3.1)

Define objective function:



Minimize the objective function:

 ${\mathrm{results}}{≔}\left[{5570.44474478066}{,}\left[{{a}}_{{0}{,}{0}}{=}{845.161626107227}{,}{{a}}_{{0}{,}{1}}{=}{-86.1947006441847}{,}{{a}}_{{0}{,}{2}}{=}{-1458.30435684866}{,}{{a}}_{{0}{,}{3}}{=}{281.463539195567}{,}{{a}}_{{1}{,}{0}}{=}{217.408601231041}{,}{{a}}_{{1}{,}{1}}{=}{741.790713963987}{,}{{a}}_{{1}{,}{2}}{=}{-2291.92998724700}{,}{{a}}_{{1}{,}{3}}{=}{-40269.8139678015}{,}{{a}}_{{2}{,}{0}}{=}{-2406.91365945783}{,}{{a}}_{{2}{,}{1}}{=}{2106.61413635412}{,}{{a}}_{{2}{,}{2}}{=}{-35753.8882512417}{,}{{a}}_{{2}{,}{3}}{=}{-291162.032188614}{,}{{a}}_{{3}{,}{0}}{=}{-378.725838677108}{,}{{a}}_{{3}{,}{1}}{=}{24869.3026839377}{,}{{a}}_{{3}{,}{2}}{=}{-349072.733326674}{,}{{a}}_{{3}{,}{3}}{=}{1.15434999607485}{×}{{10}}^{{6}}\right]\right]$ (3.2)

Assign the values corresponding to the minimum value to the parameters:

$\mathrm{assign}\left(\mathrm{results}\left[2\right]\right)$

Plot Original Data against Best Fit Surface

Original Data:

Best Fit Surface:

$\mathrm{p2}:=\mathrm{plot3d}\left(\mathrm{poly}\left(x,y\right),x=\mathrm{min}\left(X\right)..\mathrm{max}\left(X\right),y=\mathrm{min}\left(Y\right)..\mathrm{max}\left(Y\right),\mathrm{style}=\mathrm{patchnogrid},\mathrm{transparency}=0.5\right)$

$\mathrm{plots}:-\mathrm{display}\left(\mathrm{p1},\mathrm{p2}\right)$