Exemple #1
0
int main(int, char**)
{
    using namespace std;
    using mtl::lazy; using mtl::io::tout;
    typedef mtl::dense_vector<double> vt;
    
    vt v(60);
    iota(v);
    tout << "v is " << v << endl;

    mtl::mat::identity2D I(60);
    vt w1(I * v);
    tout << "I * v is " << w1 << endl;

    if (one_norm(vt(w1 - v)) > 0.001) throw "Wrong result with square identity";

    w1-= I * v;
    tout << "w1-= I * v is " << w1 << endl;
    if (one_norm(w1) > 0.001) throw "Wrong result";

    w1+= I * v;
    tout << "w1+= I * v is " << w1 << endl;
    if (one_norm(vt(w1 - v)) > 0.001) throw "Wrong result with square identity"; 

    vt w2( w1 - I * v );
    double alpha;
    (lazy(w2)= I * v) || (lazy(alpha)= lazy_dot(w2, v));

    vt w3(30), w4(90);
    mtl::mat::identity2D I3(30, 60), I4(90, 60);
    
    w3= I3 * v;
    tout << "I3 * v is " << w3 << endl;
    if (one_norm(vt(w3 - v[mtl::irange(30)])) > 0.001) throw "Wrong result with broad identity";
    
    w4= I4 * v;
    tout << "I4 * v is " << w4 << endl;
    if (one_norm(vt(w4[mtl::irange(60)] - v)) > 0.001) throw "Wrong result with long identity";
    if (one_norm(w4[mtl::irange(60, 90)]) > 0.001) throw "Wrong result with long identity";

#if 0
    mtl::dense2D<double> A(60,60);
    A=2;
    A+= A*I;
    std::cout<< "A=\n" << A << "\n";
#endif
    return 0;
}
Exemple #2
0
int main(int, char**)
{
    using namespace std;
    using mtl::lazy;
    using mtl::io::tout;
    typedef mtl::vector::dense_vector<double> vt;

    mtl::compressed2D<double> A0;
    laplacian_setup(A0, 4, 15);
    tout << "A0 is\n" << A0 << endl;

    vt v(60);
    iota(v);
    tout << "v is " << v << endl;

    vt w1(A0 * v);
    tout << "A0 * v is " << w1 << endl;

    mtl::matrix::poisson2D_dirichlet A(4, 15);
    vt  w2(60);
    w2= A * v;
    tout << "A * v is " << w2 << endl;

    if (one_norm(vt(w1 - w2)) > 0.001) throw "Wrong result";

    w2+= A * v;
    tout << "w2+= A * v is " << w2 << endl;
    if (one_norm(vt(w1 + w1 - w2)) > 0.001) throw "Wrong result";

    w2-= A * v;
    tout << "w2-= A * v is " << w2 << endl;
    if (one_norm(vt(w1 - w2)) > 0.001) throw "Wrong result";

    vt w3( w2 - A * v );
    double alpha;
    (lazy(w3)= A * v) || (lazy(alpha)= lazy_dot(w3, v));

    return 0;
}