outer product of two vectors

25 views
Skip to first unread message

Nikki Holtzer

unread,
Oct 6, 2020, 7:50:38 PM10/6/20
to deal.II User Group
Hello everyone,

I am trying to form a cross product/ outer product of two vectors of type deallii:Vector<double>. I have attempted to use some of the built in functions for the outer product from the Tensor Class but have had no luck. I can't seem to get anything other than

error: no matching function for call to 'outer_product(vec1, vec2);'

I have tried recasting my vec1/vec2 as Tensors but have run into a similar error message. 

Is there a built in vector cross product? Alternatively, how could I recast my vectors and then use the built in functions from the Tensor Class and finally recast them back into vectors? 

Thank you!

Wolfgang Bangerth

unread,
Oct 6, 2020, 8:31:47 PM10/6/20
to dea...@googlegroups.com
The easy way is to do

const unsigned int n = vec.size();
FullMatrix<double> o_p (n,n);
for (unsigned int i=0; i<n; ++i)
for (unsigned int j=0; j<n; ++j)
o_p(i,j) = vec[i] * vec[j];

But the issue is that generally you end up with a full matrix this way. Is
that what you want? How large are your vectors?

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Marc Fehling

unread,
Oct 7, 2020, 3:14:56 PM10/7/20
to deal.II User Group
Please have a look at this particular test which showcases how an outer product can be achieved with deal.II!

Hope this helps!
Marc

Nikki Holtzer

unread,
Oct 7, 2020, 3:35:34 PM10/7/20
to deal.II User Group
Thank you!
Reply all
Reply to author
Forward
0 new messages