Given a Vector
denoted v
and Matrix
denoted M
, what is the fastest method for computing the matrix quadratic form in Julia, i.e. v'Mv
? What about the most elegant?
Note: I would like the return value to be a scalar. Interestingly, if v = rand(3)
and M = rand(3, 3)
, then v'*M*v
returns a vector containing one element, not a scalar. I was not expecting this behaviour, although have read enough github issue pages to suspect there is a good reason for this behaviour that I'm just not smart enough to see. So, obviously (v'*M*v)[1]
will do the job, just wondering if there is a better method...