General LS Linear Fit finds the k-dimension linear curve values and the set of k-dimension linear fit coefficients, which describe the k-dimension linear curve that best represents the input data set using the least-squares solution. Details
![]() |
Standard Deviation is the standard deviation
![]() ![]() |
||||||||||||
![]() |
H is the matrix that represents the formula you use to fit the data set {X,Y}. H[i][j] are the function values of X[i]. | ||||||||||||
![]() |
Y Values are the observed data set Y. The number of elements in Y Values should be equal to the number of rows in H. | ||||||||||||
![]() |
covariance selector determines whether or not to compute the covariance matrix. | ||||||||||||
![]() |
algorithm specifies the algorithm the VI uses to compute Best Fit.
|
||||||||||||
![]() |
Coefficients is the set of coefficients that minimize
![]() |
||||||||||||
![]() |
Best Fit is the fitted data computed by using Coefficients. | ||||||||||||
![]() |
mse is the mean squared error. | ||||||||||||
![]() |
error returns any error or warning condition from the VI. | ||||||||||||
![]() |
Covariance is the matrix of covariances C with k-by-k elements.
![]() ![]()
![]() ![]() |
The following example demonstrates not only how to use the General LS Linear Fit VI to obtain the set of least square coefficients a and the fitted values, but also how to set up the input parameters.
The purpose is to find the set of least square coefficients a that best represent the set of data points (x,y). The relationship between x and y is of the form
where
and n is the total number of functions.
Assume the data is generated using the relationship
where
noise is a random value.
Also, assume that you think the relationship between x and y is of the form
where
To obtain the coefficients a, you must supply the set of (x,y) points in the arrays X and Y and you must also supply the basis function H(X,i), which is a 2D array, to the General LS Linear Fit VI.
The arrays X and Y are the values observed in your experiment. A way to provide the basis function H(X,i) is shown in the following block diagram.
You can easily edit the formula node to change, add, or delete functions. At this point, we have all the necessary inputs to use the General LS Linear Fit VI to solve for a. The expected set of coefficients are
a={0.0, 2.0, 1.0, 4.0, 0.0}
Executing the General LS Linear Fit VI with the values of X, Y, and H(X,i) returns the following set of coefficients.
The block diagram below demonstrates how to set up the General LS Linear Fit VI application to obtain the coefficients and a new set of y values.
The icon labeled Data Create generates the X and Y arrays. You can replace this icon with one that actually collects the data in your experiments. The icon labeled H(X,i) generates the 2D H(X,i) basis function.
The last portion of the diagram overlays the original and the estimated data points and produces a visual record of the General LS Linear Fit VI. The results are shown in the following graph.
General LS Linear Fit VI has six different algorithms to obtain the set of coefficients and the fitted values. In this example, there is no significant difference among different algorithms. You can select different algorithms from the front panel to see the results. In some cases, different algorithms may have significant differences, depending on your observed data set.