class="resources"
Finds the line values and the set of linear coefficients slope and intercept, which describe the line that best represents the input data set using the least-squares solution. Details Examples

![]() |
Y must contain at least two points. n is greater than or equal to 2. If there are fewer than two sample points, the VI sets Best Linear Fit to an empty array, sets slope, intercept, and mse to NaN, and returns an error through the Linear Fit Coefficients VI. |
![]() |
X must contain at least two points. n is greater than or equal to 2. If there are fewer than two sample points, the VI sets Best Linear Fit to an empty array, sets slope, intercept, and mse to NaN, and returns an error through the Linear Fit Coefficients VI. |
![]() |
Best Linear Fit is the calculated values of best linear fit. |
![]() |
slope is the slope of Best Linear Fit. |
![]() |
intercept is the intercept of Best Linear Fit. |
![]() |
mse is the mean squared error. |
![]() |
error returns any error or warning from the VI. You can wire error to the Error Cluster From Error Code VI to convert the error code or warning into an error cluster. |
The following equation gives the general form of the linear fit.
F = mX + b
where F represents the output sequence Best Linear Fit, X represents the input sequence X, m is the slope, and b is the intercept.
The VI calculates mse using the following equation.

where F represents the output sequence Best Linear Fit, Y represents the input sequence Y, and n is the number of data points.
Refer to the following VIs for examples of using the Linear Fit VI: