本文整理汇总了C++中teuchos::LAPACK::GELS方法的典型用法代码示例。如果您正苦于以下问题:C++ LAPACK::GELS方法的具体用法?C++ LAPACK::GELS怎么用?C++ LAPACK::GELS使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类teuchos::LAPACK
的用法示例。
在下文中一共展示了LAPACK::GELS方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Compute
//.........这里部分代码省略.........
cpts.push_back(zero);
#ifdef HAVE_TEUCHOS_COMPLEX
const std::complex<double> one(1.0,0.0);
// Construct overdetermined Vandermonde matrix
Teuchos::SerialDenseMatrix<int, std::complex<double> > Vmatrix(cpts.size(),PolyDegree_+1);
Vmatrix.putScalar(zero);
for (int jj = 0; jj <= PolyDegree_; ++jj) {
for (int ii = 0; ii < static_cast<int> (cpts.size ()) - 1; ++ii) {
if (jj > 0) {
Vmatrix(ii,jj) = pow(cpts[ii],jj);
}
else {
Vmatrix(ii,jj) = one;
}
}
}
Vmatrix(cpts.size()-1,0)=one;
// Right hand side: all zero except last entry
Teuchos::SerialDenseMatrix< int,std::complex<double> > RHS(cpts.size(),1);
RHS.putScalar(zero);
RHS(cpts.size()-1,0)=one;
// Solve least squares problem using LAPACK
Teuchos::LAPACK< int, std::complex<double> > lapack;
const int N = Vmatrix.numCols();
Teuchos::Array<double> singularValues(N);
Teuchos::Array<double> rwork(1);
rwork.resize (std::max (1, 5 * N));
std::complex<double> lworkScalar(1.0,0.0);
int info = 0;
lapack.GELS('N', Vmatrix.numRows(), Vmatrix.numCols(), RHS.numCols(),
Vmatrix.values(), Vmatrix.numRows(), RHS.values(), RHS.numRows(),
&lworkScalar, -1, &info);
TEUCHOS_TEST_FOR_EXCEPTION(info != 0, std::logic_error,
"_GELSS workspace query returned INFO = "
<< info << " != 0.");
const int lwork = static_cast<int> (real(lworkScalar));
TEUCHOS_TEST_FOR_EXCEPTION(lwork < 0, std::logic_error,
"_GELSS workspace query returned LWORK = "
<< lwork << " < 0.");
// Allocate workspace. Size > 0 means &work[0] makes sense.
Teuchos::Array< std::complex<double> > work (std::max (1, lwork));
// Solve the least-squares problem.
lapack.GELS('N', Vmatrix.numRows(), Vmatrix.numCols(), RHS.numCols(),
Vmatrix.values(), Vmatrix.numRows(), RHS.values(), RHS.numRows(),
&work[0], lwork, &info);
coeff_.resize(PolyDegree_+1);
std::complex<double> c0=RHS(0,0);
for(int ii=0; ii<=PolyDegree_; ii++) {
// test that the imaginary part is nonzero
//TEUCHOS_TEST_FOR_EXCEPTION(abs(imag(RHS(ii,0))) > 1e-8, std::logic_error,
// "imaginary part of polynomial coefficients is nonzero! coeff = "
// << RHS(ii,0));
coeff_[ii]=real(RHS(ii,0)/c0);
//std::cout<<"coeff["<<ii<<"]="<<coeff_[ii]<<std::endl;
}
#else
// Construct overdetermined Vandermonde matrix
Teuchos::SerialDenseMatrix< int, double > Vmatrix(xs.size()+1,PolyDegree_+1);
Vmatrix.putScalar(0.0);