Nonlinear Fitting

cancel
Showing results for 
Search instead for 
Did you mean: 

Forum Examples for 2D Fitting

Over the years, many examples of nonlinear fitting with 2 independent variables have been posted in the LabVIEW forum. This documents is a repository of links to such discussions. Please suggest other forum links in the comment section below. A similar document for 1D fits can be found here.

 

There are several types of 2D problems. In the simplest case, the independent variables forms a regular 2D grid (e.g. an image or a 2D array, where x and y are indices and Z are the values). In other cases, the function is only defined for scattered pairs of x and y.

 

Basically, we simply want to fit z = f(x,y).

 

Many of the same techniques can easily be adapted for problems with more than 2 independent variables. The important thing to know is that Nonlinear Fit only accepts 1D arrays. The technique is typically to reshape the multidimensional array to a 1D array with the same number of points, then reshape the best fit result back to the original arrangment. Fitting does not care how the points are arranged as long as the model knows the arrangement used. The X input is also 1D DBL, so cannot be used directly. Fortunately the internal code is such that it does not care about the size of the x array with respect to the size of the Y array, so it can be used to wire an array of twice the size with the x,y coordinates interlaced. Sometimes it is computationally easier to represent the independent variables as a complex array. This is not compatible with the x input, but we can send it via the data variant input to the model while leaving the x input unwired.

 

 

Gridded Data

 

Fitting of a 2D gaussian including assymetry and rotation.

Scroll down for variations such as simplifications to symmetric data or including a z offset. This can be used for example to measure a laser beam profile.

 

 

Fitting of a 2D Gaussian and displaying it in 3D.

There are also links to earlier posts, e.g. here)

 

 

Fit of an image dot to a 2D sinc function.

Use of a precomputed complex grid for the independent variables dramatically simplify the model (no FOR loop!)

http://forums.ni.com/ni/attachments/ni/170/761554/1/2DsincSquaredModel.png

 

 

 

Fit a 2D array to a 2D polynomial, skipping all values that are NaN

 

 

 

 

Scattered Data

 

Fitting of a complicated model with two independent variables.

To be fit is the function z(t)=(a+b*x+c*x^2+d*x^3+e*x^4)*y+A*x*exp(B*x) with x and y as independent variables.

 

Fitting of a complicated polynomial (not all terms) using general linear fit.

Fitting scattered xyz data and graphing a gridded surface best on the best fit coefficients.

 

0 Kudos
Message 1 of 1
(7,642 Views)