can someone please provide an example of how to use uBLAS product to multiply things? Or if there's a nicer C++ matrix library you can recommend I'd welcome that too. This is turning into one major headache.
Here's my code:
vector<double> myVec(scalar_vector<double>(3));
matrix<double> myMat(scalar_matrix<double>(3,3,1));
matrix<double> temp = prod(myVec, myMat);
Here's the error:
cannot convert from 'boost::numeric::ublas::matrix_vector_binary1<E1,E2,F>' to 'boost::numeric::ublas::matrix<T>'
I have exhausted my search. Stackoverflow has a question about this here. Boost documentation has an example here. I've copied the code from example, but it's of no use to me because the template magic that works for stdout is useless to me.
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
vector<double> v (3);
for (unsigned i = 0; i < std::min (m.size1 (), v.size ()); ++ i) {
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = 3 * i + j;
v (i) = i;
}
std::cout << prod (m, v) << std::endl;
std::cout << prod (v, m) << std::endl;
}
The first component of the matrix-vector product is the dot product of x with the first row of A, etc. In fact, if A has only one row, the matrix-vector product is really a dot product in disguise.
And this is a important takeaway. Matrix multiplication or matrix products with vectors is always a linear transformation.
The product of a vector and a matrix is a vector, not a matrix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With