Suppose that you have collected samples from a transducer (Y Values) and you want to solve for the coefficients of the model:
To build H, you set each column to the independent functions evaluated at each x value. Assuming there are 100 × values, H would be:
Given that you have the independent X Values and observed Y Values, the following block diagram demonstrates how to build H and use the General LS Linear Fit VI.
The General LS Linear Fit Problem can be described as follows.
Given a set of observation data, find a set of coefficients that fit the linear "model".
where b is the set of Coefficients, n is the number of elements in Y Values and the number of rows of H, and k is the number of Coefficients.
is your observation data, which is contained in H.
Equation (1) can also be written as Y=HB.
This is a multiple linear regression model, which uses several variables to predict one variable
. In contrast, the Linear Fit, Exponential Fit, and Polynomial Fit VIs are all based on a single predictor variable, which uses one variable to predict another variable.
In most cases, we have more observation data than coefficients. The equations in (1) may not have the solution. The fit problem becomes to find the coefficients B that minimizes the difference between the observed data, and the predicted value
This VI uses the least chi-square plane method to obtain the coefficients in (1), that is, finding the solution, B, which minimizes the quantity:
(2)
where
In this equation, is the Standard Deviation. If the measurement errors are independent and normally distributed with constant standard deviation,
the preceding equation is also the least square estimation.
There are different ways to minimize .
One way to minimize is to set the partial derivatives of
to zero with respect to
.
The preceding equations can be derived to:
(3)
is the transpose of
.
Equations (3) are also called normal equations of the least-square problems. You can solve them using LU or Cholesky factorization algorithms, but the solution from the normal equations is susceptible to roundoff error.
An alternative, and preferred way to minimize is to find the least square solution of equations
You can use QR or SVD factorization to find the solution, B. For QR factorization, you can choose Householder, Givens, and Givens2 (also called fast Givens).
Different algorithms can give you different precision, and in some cases, if one algorithm cannot solve the equation, perhaps another algorithm can. You can try different algorithms to find the best one based on your observation data.
The Covariance matrix C is computed as
The Best Fit Z is given by
The mse is obtained using the following formula.
The polynomial fit that has a single predictor variable can be thought of as a special case of multiple regression. If the observation data sets are where i = 0, 1, ..., n 1, the model for polynomial fit is:
![]() | (4) |
i = 0, 1, 2,..., n 1.
Comparing equations (1) and (4) shows that. In other words,
In this case, you can build H as follows:
Instead of using , you can also choose another function formula to fit the data sets
. In general, you can select
. Here,
is the function model that you choose to fit your observation data. In polynomial fit,
.
In general, you can build H as follows:
Your fit model is: