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.
#include <iostream> // 1
#include <rw/math/genmat.h>
#include <rw/math/mathvec.h>
#include <rw/lapack/lsqr.h>
#include <rw/lapack/qrcalcp3.h>
int main()
{
RWGenMat<float> A; // 2
RWMathVec<float> b;
std::cin >> A >> b;
RWLeastSqQR<float, RWQRCalcP3<float> > ls(A); // 3
RWMathVec<float> x = ls.solve(b); // 4
std::cout << x << std::endl;
return 0;
}