Home
Products
Support
Blog
Resources
Company
NMath Matrix User's Guide
TOC |  Previous |  Next |  Index

6.3 Using Least Squares Objects

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.

Testing for Goodness

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.

Solving 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.

Retrieving Information About the Original Matrix

Read-only properties are also provided for retrieving information about the original matrix A:

For example:

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

Copyright © 2008 CenterSpace Software, LLC. All rights reserved.
All trademarks and registered trademarks mentioned on this web site are the property of their respective owners.
Contact Webmaster