This example shows the effect of a regularization parameter when solving an overdetermined system. In this example, a quantity y
is measured at several different values of time t
to produce the following observations.
Model the data with a decaying exponential function
.
The preceding equation says that the vector y
should be approximated by a linear combination of two other vectors. One is a constant vector containing all ones and the other is the vector with components exp(-t)
. The unknown coefficients, and , can be computed by doing a least-squares fit, which minimizes the sum of the squares of the deviations of the data from the model. There are six equations and two unknowns, represented by a 6-by-2 matrix.
E = 6×2
1.0000 1.0000
1.0000 0.7408
1.0000 0.4493
1.0000 0.3329
1.0000 0.2019
1.0000 0.1003
Use the fixed.qrMatrixSolve
function to get the least-squares solution.
In other words, the least-squares fit to the data is
The following statements evaluate the model at regularly spaced increments in t
, and then plot the result together with the original data:
In cases where the input matrices are ill-conditioned, small positive values of a regularization parameter can improve the conditioning of the least squares problem, and reduce the variance of the estimates. Explore the effect of the regularization parameter on the least squares solution for this data.