Boost logo

Glas :

[glas] How to multiply a matrix on a vector?

From: Tsai Dung-Bang (dbtsai_at_[hidden])
Date: 2007-05-16 22:47:41


I have the following simple code, I want multiply a matrix on a vector
and then obtain another vector. Unfortunately, the code can not
compile, and with error message

#include <boost/numeric/ublas/hermitian.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>

int main ()
{
    using namespace boost::numeric::ublas;

    vector<std::complex<double> > v(2);
    v(0) = std::complex<double> (3,2);
    v(1) = std::complex<double> (1,3);

    hermitian_matrix<std::complex<double>, upper> H(2,2);
    H(0,0) = 1; H(0,1) = 0; H(1,0) = 0; H(1,1) = -1;

    std::cout << "H="<<H<<std::endl<<"V="<<v<<std::endl<<"HV="<<H*v;

    return 0;
}

Thanks.

Tsai Dung-Bang

Compiling: /home/dbtsai/qis_code/my_code/test_case/boost_matrix_vector_test.cpp
/home/dbtsai/qis_code/my_code/test_case/boost_matrix_vector_test.cpp:
In function 「int main()」:
/home/dbtsai/qis_code/my_code/test_case/boost_matrix_vector_test.cpp:18:
error: ambiguous overload 為 「operator*」 在 「H * v」 中
/usr/include/boost/numeric/ublas/vector_expression.hpp:1113: 附註: 備選為:
typename boost::numeric::ublas::vector_binary_scalar1_traits<const T1,
E2, boost::numeric::ublas::scalar_multiplies<T1, typename
E2::value_type> >::result_type boost::numeric::ublas::operator*(const
T1&, const boost::numeric::ublas::vector_expression<E2>&) [with T1 =
boost::numeric::ublas::hermitian_matrix<std::complex<double>,
boost::numeric::ublas::basic_upper<unsigned int>,
boost::numeric::ublas::basic_row_major<unsigned int, int>,
boost::numeric::ublas::unbounded_array<std::complex<double>,
std::allocator<std::complex<double> > > >, E2 =
boost::numeric::ublas::vector<std::complex<double>,
boost::numeric::ublas::unbounded_array<std::complex<double>,
std::allocator<std::complex<double> > > >]
/usr/include/boost/numeric/ublas/matrix_expression.hpp:3228: 附註:
   typename boost::numeric::ublas::matrix_binary_scalar2_traits<E1,
const T2, boost::numeric::ublas::scalar_multiplies<typename
E1::value_type, T2> >::result_type
boost::numeric::ublas::operator*(const
boost::numeric::ublas::matrix_expression<E>&, const T2&) [with E1 =
boost::numeric::ublas::hermitian_matrix<std::complex<double>,
boost::numeric::ublas::basic_upper<unsigned int>,
boost::numeric::ublas::basic_row_major<unsigned int, int>,
boost::numeric::ublas::unbounded_array<std::complex<double>,
std::allocator<std::complex<double> > > >, T2 =
boost::numeric::ublas::vector<std::complex<double>,
boost::numeric::ublas::unbounded_array<std::complex<double>,
std::allocator<std::complex<double> > > >]
Process terminated with status 1 (0 minutes, 1 seconds)
3 errors, 0 warnings