Admin Production ni-theme
Current Publication

GenLSFitCoef

LabWindows/CVI

GenLSFitCoef

Advanced Analysis Library Only

AnalysisLibErrType GenLSFitCoef (void *hMatrix, ssize_t numberOfRows, ssize_t numberOfColumns, double yArray[], double coefficientArray[], int algorithm);

Purpose

Finds the set of linear fit coefficients, which describe the linear curve that best represents the input data that GenLSFitCoef uses to obtain the least squares solution technique. The general form of the k-dimension linear fit is as follows:

Let i = 0, 1, . . ., n be your ith observation
xij, ..., xik – 1 be k —1 observed x points
yi be observed y points

Compose the HMatrix as follows:

GenLSFitCoef obtains the general LS linear fit coefficient bk by minimizing the quantity:

Parameters

Input
Name Type Description
hMatrix void * Input matrix that represents the formula you use to fit the data set (x,y). Hij are the function values of Xi.
numberOfRows ssize_t Number of rows in HMatrix and the number of elements in YArray.
numberOfColumns ssize_t Number of columns in HMatrix and the number of elements in coefficientArray.
yArray double [] Array that contains the y-coordinates of the (x, y) data sets to fit.
algorithm int Algorithm used to solve the multiple linear regression model.

The algorithm has the following possible values.

  • ALGORITHM_SVD (0)—Use Singular Value Decomposition to solve the multiple linear regression model. This value is the default.
  • ALGORITHM_GIVENS (1)—Use Givens Decomposition to solve the multiple linear regression model.
  • ALGORITHM_GIVENS2 (2)—Use Square Root Free Givens Decomposition to solve the multiple linear regression model.
  • ALGORITHM_HOUSEHOLD (3)—Use Householder Transformation to solve the multiple linear regression model.
  • ALGORITHM_LU_DECOMP (4)—Use LU Decomposition to solve the multiple linear regression model.
  • ALGORITHM_CHOLESKY (5)—Use Cholesky Decomposition to solve the multiple linear regression model. Each algorithm might offer different precision depending on the input data. Given the coefficient vector coefficientArray and HMatrix, GenLSFitCoef can calculate the fitted data zi by a simple matrix multiplication:

    Z = H × b

    and can calculate the mean squared error with the following formula:

    genlscoefmse.gif
Output
Name Type Description
coefficientArray double [] The set of linear coefficients that best fit the multiple linear regression model in a least squares sense.

The size of this array must be at least numberOfColumns.

Return Value

Name Type Description
status AnalysisLibErrType A value that specifies the type of error that occurred. Refer to analysis.h for definitions of these constants.

Additional Information

Library: Advanced Analysis Library

Include file: analysis.h

LabWindows/CVI compatibility: LabWindows/CVI 3.1 and later