Ejemplo n.º 1
0
 void compute( const FUNC& f, const X & x, const o_t & o)
 {
   real_t tmptol = tol_;
   init(o, x);
   BOOST_AUTO_TPL(dif, nt2::abs(nt2::diff(nt2::rowvect(wpts_))));
   real_t tol1= tol_/nt2::globalasum1(dif);
   size_t l = numel(dif);
   res_.resize(extent(wpts_));
   res_(1) = nt2::Zero<value_t>();
   tol_ = tol1*dif(1);
   res_(2) = compute<true>(f, wpts_(1), wpts_(2));
   for(size_t i=2; i < l; ++i)
   {
     tol_ = tol1*dif(i);
     res_(i+1) = res_(i)+compute<false>(f, wpts_(i), wpts_(i+1));
   }
   if (l >= 2)
   {
     tol_ = tol1*dif(l);
     res_(l+1) = res_(l)+compute<true>(f, wpts_(l), wpts_(l+1));
   }
   tol_ = tmptol;
   if (!o.return_waypoints)
   {
     res_(begin_) = res_(end_);
     res_.resize(nt2::of_size(1, 1));
   }
 }
void dtkMatrixOperationsTestCase::testSolve(void)
{
    dtkUnderscore _;

    //Matrix-vector
    dtkDenseMatrix<double> a(4,4);
    a(1,_)=8.,6.,9.,9.;
    a(2,_)=9.,0.,9.,4.;
    a(3,_)=1.,2.,1.,8.;
    a(4,_)=9.,5.,9.,1.;

    dtkDenseVector<double> b(4); b = 1,2,3,4;
    dtkDenseVector<double> x=dtk::lapack::solve(a,b);

    dtkDenseVector<double> res(4); res = 5.34263959,0.53553299,-5.22081218,0.22588832;

    for(int i=1;i<5;i++)
        QVERIFY(abs(res(i)-x(i))<1e-7);

    dtkDenseMatrix<double> a_(4,3);
    dtkDenseVector<double> b_(4);


    a_(_,1)=1.,0.,0.,0.;
    a_(_,2)=0.,1.,0.,0.;
    a_(_,3)=0.,0.,1.,1.;

    b_ = 1, 2, 2, 1;

    dtkDenseVector<double> res_(3); res_ = 1, 2, 1.5;

    dtkDenseVector<double> x_= dtk::lapack::solve(a_,b_);
    for(int i = 1; i < x_.length(); ++i) {
        QVERIFY((x_(i) - res_(i)) < 1e-7);
    }

}