Vectorize product cell vectors
Afficher commentaires plus anciens
I need to efficiently compute the quantity
where
and
,
, are
vectors and
are
sparse matrices.
If the matrices
were not sparse, then I could use a 3D array and probably vectorize some of the operations.
Right now, I am using a cell structure to store the matrices and I store the vectors in
matrices.
Here's the relevant part of the code that I am using:
res = 1;
for k = 1:N
res = res * (u(:, k).' * A{k} * v(:, k));
end
For reference, in my case
and
0, and the loop takes about 2 seconds. In my code, this loop is called several times, so it would make a great impact to reduce its runtime.
How can I improve the performance of the loop? Can it be vectorized? Should I be computing it in another way?
Thank you.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!