Bivariate Polynomial Regression - Maple Programming Help

Online Help

All Products    Maple    MapleSim


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 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:=nj=0ni=0nai,jxiyj

fn→j=0ni=0nai,jxiyj

(2.1)

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

f2

x2y2a2,2+x2ya2,1+xy2a1,2+x2a2,0+xya1,1+y2a0,2+xa1,0+ya0,1+a0,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

n3

(2.3)

poly  unapplyfn,x,y

polyx,y→x3y3a3,3+x3y2a3,2+x2y3a2,3+x3ya3,1+x2y2a2,2+xy3a1,3+x3a3,0+x2ya2,1+xy2a1,2+y3a0,3+x2a2,0+xya1,1+y2a0,2+xa1,0+ya0,1+a0,0

(2.4)

 

Calculate Parameters by Least Squares Minimization

 

Separate and normalize the data

withLinearAlgebra:

X  Normalizedata.., 1, Euclidean

Error, (in LinearAlgebra:-Normalize) invalid input: LinearAlgebra:-Normalize expects its 1st argument, V, to be of type Vector() but received data[() .. (), 1] |lib/LinearAlgebra/Standard/src/Normalize.mm:18|

Y  Normalizedata.., 2, Euclidean

Error, (in LinearAlgebra:-Normalize) invalid input: LinearAlgebra:-Normalize expects its 1st argument, V, to be of type Vector() but received data[() .. (), 2] |lib/LinearAlgebra/Standard/src/Normalize.mm:18|

Z  data.., 3

Zdata..,3

(3.1)

nRows  RowDimensiondata

Error, (in LinearAlgebra:-RowDimension) invalid input: LinearAlgebra:-RowDimension expects its 1st argument, A, to be of type Matrix() but received data |lib/LinearAlgebra/Queries/src/RowDimension.mm:17|

Define objective function:

sse  addpolyXi, YiZi2, i = 1 .. nRows :

Error, unable to execute add |lib/LinearAlgebra/Queries/src/RowDimension.mm:17|

Minimize the objective function:

results  Optimization:-Minimizesse, iterationlimit = 10000000

Error, (in Optimization:-LPSolve) problem is unbounded as no constraints were found |lib/Optimization/src/LPSolve.mm:90|

 

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

assignresults2

 

Plot Original Data against Best Fit Surface

Original Data:

p1  plotspointplot3dX,Y,Z,color=black,symbol=solidsphere,symbolsize=10

Error, (in plots:-pointplot3d) points cannot be converted to floating-point values |lib/plots/src/plots.mpl:404|

Best Fit Surface:

p2:=plot3dpolyx,y,x=minX..maxX,y=minY..maxY,style=patchnogrid,transparency=0.5

Error, (in plot3d) bad range arguments: x = X .. X, y = Y .. Y |lib/src/plot3d.mpl:43|

plotsdisplayp1,p2

Error, (in plots:-display) expecting plot structure but received: p1 |lib/plots/src/plots.mpl:199|