Glas :Re: [glas] How to multiply a matrix on a vector? |
From: Tsai Dung-Bang (dbtsai_at_[hidden])
Date: 2007-05-16 23:26:46
sorry, I find that I have to use the function prod(H,v) to do the operation.
I have another question, why not overload the operator * such that we
can simply use H*v?
Thanks
2007/5/17, Tsai Dung-Bang <dbtsai_at_[hidden]>:
> 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
>