This example shows an NLREG program that fits a plane in 3-dimensional
space to a set of data points whose X,Y,Z coordinates are specified.

In this example, the plane is fitted so as to minimize the sum of the
squared *Z* (vertical) distances of the points from the plane.
For an NLREG example that minimizes the distances of the points to the plane
along lines perpendicular (normal) to the plane,
click here

The implicit equation for a plane in 3D space is

ax + by + cz + d = 0

We can simplify this equation and eliminate the *c* parameter by dividing by *c* to get

ax + by + z + d = 0

Transposing to get *z* as the dependent variable produces

z = -ax - by - d

This equation is used in the following NLREG to fit the plane to a set of data points whose X, Y and Z
coordinaes are specified.

Title "Fit plane to data points in 3D space";
Variables X, Y, Z;
Parameters a, b, d;
Function z = -a*X - b*Y - d;
Plot;
Data;
[data values go here]

Here is a surface plot generated by NLREG showing the fitted plane: