Bivariate Polynomial Regression - Maple Help

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)$

 ${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.

 ${3}$ (2.3)

 $\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):$

 $\left[\begin{array}{c}{\mathrm{1 .. 176}}{{\mathrm{Vector}}}_{{\mathrm{column}}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (3.1)

 $\left[\begin{array}{c}{\mathrm{1 .. 176}}{{\mathrm{Vector}}}_{{\mathrm{column}}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (3.2)

 $\left[\begin{array}{c}{\mathrm{1 .. 176}}{{\mathrm{Vector}}}_{{\mathrm{column}}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (3.3)

 ${176}$ (3.4)

Define objective function:



Minimize the objective function:

 $\left[{5570.44474478066}{,}\left[{{a}}_{{0}{,}{0}}{=}{845.161626107228}{,}{{a}}_{{0}{,}{1}}{=}{-}{86.1947006441850}{,}{{a}}_{{0}{,}{2}}{=}{-}{1458.30435684886}{,}{{a}}_{{0}{,}{3}}{=}{281.463539195548}{,}{{a}}_{{1}{,}{0}}{=}{217.408601231052}{,}{{a}}_{{1}{,}{1}}{=}{741.790713964468}{,}{{a}}_{{1}{,}{2}}{=}{-}{2291.92998724876}{,}{{a}}_{{1}{,}{3}}{=}{-}{40269.8139678463}{,}{{a}}_{{2}{,}{0}}{=}{-}{2406.91365945805}{,}{{a}}_{{2}{,}{1}}{=}{2106.61413635431}{,}{{a}}_{{2}{,}{2}}{=}{-}{35753.8882512103}{,}{{a}}_{{2}{,}{3}}{=}{-}{2.91162032188594}{}{{10}}^{{5}}{,}{{a}}_{{3}{,}{0}}{=}{-}{378.725838677840}{,}{{a}}_{{3}{,}{1}}{=}{24869.3026838967}{,}{{a}}_{{3}{,}{2}}{=}{-}{3.49072733326538}{}{{10}}^{{5}}{,}{{a}}_{{3}{,}{3}}{=}{1.15434999607880}{}{{10}}^{{6}}\right]\right]$ (3.5)

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)$