Bivariate Polynomial Regression - Maple Programming Help

Home : Support : Online Help : Applications and Example Worksheets : Science and Engineering : applications/BivariatePolynomialRegression

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]{5.0px}{0.0ex}}{\sum }_{{i}{=}{0}}^{{n}}\phantom{\rule[-0.0ex]{5.0px}{0.0ex}}{{a}}_{{i}{,}{j}}{}{{x}}^{{i}}{}{{y}}^{{j}}$ (2.1)

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

$f\left(2\right)$

 ${{x}}^{{2}}{}{{y}}^{{2}}{}{{a}}_{{2}{,}{2}}{+}{{x}}^{{2}}{}{y}{}{{a}}_{{2}{,}{1}}{+}{x}{}{{y}}^{{2}}{}{{a}}_{{1}{,}{2}}{+}{{x}}^{{2}}{}{{a}}_{{2}{,}{0}}{+}{x}{}{y}{}{{a}}_{{1}{,}{1}}{+}{{y}}^{{2}}{}{{a}}_{{0}{,}{2}}{+}{x}{}{{a}}_{{1}{,}{0}}{+}{y}{}{{a}}_{{0}{,}{1}}{+}{{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}}{}{{y}}^{{3}}{}{{a}}_{{3}{,}{3}}{+}{{x}}^{{3}}{}{{y}}^{{2}}{}{{a}}_{{3}{,}{2}}{+}{{x}}^{{2}}{}{{y}}^{{3}}{}{{a}}_{{2}{,}{3}}{+}{{x}}^{{3}}{}{y}{}{{a}}_{{3}{,}{1}}{+}{{x}}^{{2}}{}{{y}}^{{2}}{}{{a}}_{{2}{,}{2}}{+}{x}{}{{y}}^{{3}}{}{{a}}_{{1}{,}{3}}{+}{{x}}^{{3}}{}{{a}}_{{3}{,}{0}}{+}{{x}}^{{2}}{}{y}{}{{a}}_{{2}{,}{1}}{+}{x}{}{{y}}^{{2}}{}{{a}}_{{1}{,}{2}}{+}{{y}}^{{3}}{}{{a}}_{{0}{,}{3}}{+}{{x}}^{{2}}{}{{a}}_{{2}{,}{0}}{+}{x}{}{y}{}{{a}}_{{1}{,}{1}}{+}{{y}}^{{2}}{}{{a}}_{{0}{,}{2}}{+}{x}{}{{a}}_{{1}{,}{0}}{+}{y}{}{{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):$

 ${Z}{≔}{{\mathrm{data}}}_{\left({}\right){..}\left({}\right){,}{3}}$ (3.1)

Define objective function:



Minimize the objective function:

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}\left[\mathrm{display}\right]\left(\mathrm{p1},\mathrm{p2}\right)$