Say I am given a row vector psi
of length P
and a row vector q
of length M
in MATLAB. Here, M>P
. I want to assemble G
in the following way:
for j = 1:M
G(j) = q(j:min(j+P-1, M))*psi(1:min(M-j+1, P))';
end
For large M
, P
, this is very time consuming. It is also delicate to the size of q
and psi
changing for large j
.
I have not been able to vectorize this, also due to j moving. Of course, one could write this as a matrix-vector multiplication with psi
being the vector, but assembling the correct matrix looks almost equally expensive to me.
I appreciate any sort of help.
Hyperbolic PDE friend is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.