Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Linear Algebra Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

5.2 Solving a Least Squares Problem

Here is a simple program which reads in a matrix and a right side, builds a least squares factorization object, and then calculates the solution to the least squares problem. The program is nearly identical to the first factorization example problem in the previous chapter.

//1

The header file lsqr.h includes the declaration of the least squares class RWLeastSqQR<T,QRCalc>. This is the QR decomposition implementation of the least squares class. Other implementations are described subsequently.

//2

Here the matrix A and the vector b are defined and read from standard input.

//3

The least squares decomposition is created from the matrix A. The second template parameter for the class RWLeastSqQR indicates that we are using the class RWQRCalcP3<float> to compute the QR decomposition of A.

//4

The solution vector is calculated. If the system is overdetermined, this will be the solution that best fits in a least squares sense. If the system is underdetermined, this will be the solution with the smallest norm.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.