How to multiply a matrix on a vector?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to multiply a matrix on a vector?

Tsai Dung-Bang
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
_______________________________________________
glas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/glas
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to multiply a matrix on a vector?

Tsai Dung-Bang
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 <[hidden email]>:

> 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
>
_______________________________________________
glas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/glas
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to multiply a matrix on a vector?

Bugzilla from nomis80@nomis80.org
On Wednesday 16 May 2007 23:26, Tsai Dung-Bang wrote:
> I have another question, why not overload the operator * such that we
> can simply use H*v?

This is the glas mailing list. What you're looking for is here:

http://lists.boost.org/mailman/listinfo.cgi/ublas
_______________________________________________
glas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/glas
Loading...