# Better way than using multiple flattens?

I am running some calculations with vectors (lists) and in order to perform them, they need to be flattened. Is there a better or neater way to do this?

ReactionPower = Flatten[RF1].Flatten[RF1vel] + Flatten[RF2].Flatten[RF2vel];


All the variables are of the form:

RF1 = {{x},{y}}


x and y are not integers, but long expressions with trigonometric functions.

• What do RF1, RF1vel, RF2, and RF2vel look like before Flatten[]-ing? Apr 15 '17 at 0:56
• @J.M. All are of the form {{ }, { }} Apr 15 '17 at 0:59
• Ah, so ReactionPower is a scalar? Apr 15 '17 at 1:01
• @J.M. Correct and the variables on the RHS are x and y components Apr 15 '17 at 1:04
• Maybe a route that is "better ... than using multiple Flatten[]s..." can be had if you modify the process generating those lists to be Flatten[]-ed. Apr 15 '17 at 1:06

Given:

rf1 = {{x1}, {y1}};
rf2 = {{x2}, {y2}};
rf1vel = {{vx1}, {vy1}};
rf2vel = {{vx2}, {vy2}};


Here is a way using Total:

reactionPower = Total[rf1*rf1vel + rf2*rf2vel, 2]
(* vx1 x1 + vx2 x2 + vy1 y1 + vy2 y2 *)

reactionPower === Flatten[rf1].Flatten[rf1vel] + Flatten[rf2].Flatten[rf2vel]
(* True *)


This will certainly be less efficient, but is slightly shorter:

ReactionPower = Tr[RF1.Transpose[RF1vel] + RF2.Transpose[RF2vel]];