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:=n→∑j=0n∑i=0nai,j⁢xi⁢yj
n→∑j=0n∑i=0nai,j⁢xi⁢yj
For example, the general form for a bivariate quadratic is:
f2
x2⁢y2⁢a2,2+x2⁢y⁢a2,1+x⁢y2⁢a1,2+x2⁢a2,0+x⁢y⁢a1,1+y2⁢a0,2+x⁢a1,0+y⁢a0,1+a0,0
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
3
poly ≔ unapplyfn,x,y
x,y→x3⁢y3⁢a3,3+x3⁢y2⁢a3,2+x2⁢y3⁢a2,3+x3⁢y⁢a3,1+x2⁢y2⁢a2,2+x⁢y3⁢a1,3+x3⁢a3,0+x2⁢y⁢a2,1+x⁢y2⁢a1,2+y3⁢a0,3+x2⁢a2,0+x⁢y⁢a1,1+y2⁢a0,2+x⁢a1,0+y⁢a0,1+a0,0
Calculate Parameters by Least Squares Minimization
Separate and normalize the data
withLinearAlgebra:
X ≔ Normalizedata.., 1, Euclidean
1 .. 176 VectorcolumnData Type: float8Storage: rectangularOrder: Fortran_order
Y ≔ Normalizedata.., 2, Euclidean
Z ≔ data.., 3
nRows ≔ RowDimensiondata
176
Define objective function:
sse ≔ addpolyXi, Yi−Zi2, i = 1 .. nRows :
Minimize the objective function:
results ≔ Optimization:-Minimizesse, iterationlimit = 10000000
5570.44474478066,a0,0=845.161626107228,a0,1=−86.1947006441850,a0,2=−1458.30435684886,a0,3=281.463539195548,a1,0=217.408601231052,a1,1=741.790713964468,a1,2=−2291.92998724876,a1,3=−40269.8139678463,a2,0=−2406.91365945805,a2,1=2106.61413635431,a2,2=−35753.8882512103,a2,3=−2.91162032188594⁢105,a3,0=−378.725838677840,a3,1=24869.3026838967,a3,2=−3.49072733326538⁢105,a3,3=1.15434999607880⁢106
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
Best Fit Surface:
p2:=plot3d⁡poly⁡x,y,x=min⁡X..max⁡X,y=min⁡Y..max⁡Y,style=patchnogrid,transparency=0.5
plotsdisplay⁡p1,p2
Download Help Document
What kind of issue would you like to report? (Optional)