Commit 83928b30 authored by Basile Sauvage's avatar Basile Sauvage

correction des produits matrice/vecteur et vecteur/matrice

parent 218a41b3
......@@ -161,7 +161,11 @@ class Matrix
// Vector / Matrix multiplication
template <unsigned int M, unsigned int N, typename T>
Vector<M,T> operator*(const Vector<N,T>& v, const Matrix<M,N,T>& m) ;
Vector<N,T> operator*(const Vector<M,T>& v, const Matrix<M,N,T>& m) ;
// Matrix / Vector multiplication
template <unsigned int M, unsigned int N, typename T>
Vector<M,T> operator*(const Matrix<M,N,T>& m,const Vector<N,T>& v) ;
// Scalar / Matrix multiplication
template <unsigned int M, unsigned int N, typename T>
......
......@@ -431,13 +431,25 @@ std::istream& operator>>(std::istream& in, Matrix<M,N,T>& m)
template <unsigned int M, unsigned int N, typename T>
Vector<N,T> operator*(const Vector<M,T>& v, const Matrix<M,N,T>& m)
{
Vector<N,T> res ;
Vector<N,T> res (0);
for(unsigned int i = 0; i < M; ++i)
for(unsigned int j = 0; j < N; ++j)
res[j] += m(i,j) * v[i] ;
return res ;
}
// Matrix / Vector multiplication
template <unsigned int M, unsigned int N, typename T>
Vector<M,T> operator*(const Matrix<M,N,T>& m,const Vector<N,T>& v) {
Vector<M,T> res (0);
for(unsigned int i = 0; i < M; ++i)
for(unsigned int j = 0; j < N; ++j)
res[i] += m(i,j) * v[j] ;
return res ;
}
// Scalar / Matrix multiplication
template <unsigned int M, unsigned int N, typename T>
Matrix<M,N,T> operator*(T s, const Matrix<M,N,T>& m)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment