Faster projected-norm (quadratic-form, metric-matrix...) style computations

Posted by thekindamzkyoulike on Stack Overflow See other posts from Stack Overflow or by thekindamzkyoulike
Published on 2010-04-02T20:13:20Z Indexed on 2010/04/02 20:33 UTC
Read the original article Hit count: 418

Filed under:
|

I need to perform lots of evaluations of the form

X(:,i)' * A * X(:,i)   i = 1...n

where X(:,i) is a vector and A is a symmetric matrix. Ostensibly, I can either do this in a loop

for i=1:n
    z(i) = X(:,i)' * A * X(:,i)
end

which is slow, or vectorise it as

z = diag(X' * A * X)

which wastes RAM unacceptably when X has a lot of columns. Currently I am compromising on

Y = A * X
for i=1:n
    z(i) = Y(:,i)' * X(:,i)
end

which is a little faster/lighter but still seems unsatisfactory.

I was hoping there might be some matlab/scilab idiom or trick to achieve this result more efficiently?

© Stack Overflow or respective owner

Related posts about matlab

Related posts about scilab