Once a least squares object has been constructed from a matrix (Section 6.2), it may be used to solve least squares problems, if the factorization or decomposition was successful.
Read-only properties are provided for determining whether the decomposition method was successful. The SVD least squares classes provide a Fail property that returns true if the SVD algorithm failed to converge.
Other methods are guaranteed to complete, but the resultant object may still be unusable for solving least squares problems, if for example the original matrix A was not of full rank. All least squares classes therefore provide an IsGood property that returns true if the method succeeded and the decomposition can be used to solve least squares problems.
All least squares classes provide a Solve() method that accepts a vector y, and computes the solution to the least squares problem
. For example:
int rows = 6, cols = 3; RandGenUniform rng = new RandGenUniform( -2, 2 ); DoubleMatrix A = GenerateData( rows, cols, rng ); DoubleCholeskyLeastSq lsq = new DoubleCholeskyLeastSq( A ); DoubleVector y = new DoubleVector( rows, rng ); if ( lsq.IsGood ) { DoubleVector x = lsq.Solve( y ); }
Method ResidualVector() returns the residual vector
; ResidualNormSqr() computes the 2-norm squared of the residual vector. Finally, an existing least squares object can factor other matrices using the Factor() method.
Read-only properties are also provided for retrieving information about the original matrix A:
DoubleComplexMatrix A = new DoubleComplexMatrix( "4x2[ (1,0) (0,0) (0,0) (1,0) (0,0) (0,0) (0,0) (0,0) ]" ); DoubleComplexQRLeastSq lsq = new DoubleComplexQRLeastSq( A ); int rank = lsq.Rank;TOC | Previous | Next | Index