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.
#include <iostream.h> // 1 #include <rw/flsqr.h> main() { RWGenMat<float> A; // 2 RWMathVec<float> b; cin >> A >> b; FloatLeastSqQR ls(A); // 3 RWMathVec<float> x = solve(ls, b); // 4 cout << x << endl; }
//1 | The header file fchls.h includes the declaration of the least squares class FloatLeastSqQR. 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. |
//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. |
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.