How do I vectorize the following the summation?
Afficher commentaires plus anciens
This is the code that I have. It's taking up way too much time so I was wondering if it is possible to 'vectorize' it, to save time. Here's the code:
Sigma=zeros(n,n);
G=zeros(n,n);
for i=1:m
Sigma=(y(i)-x(i,:)*bhat).^2*(x(i,:)).'*x(i,:)+Sigma;
G=*(x(i,:)).'*x(i,:)+G;
end
Where x is a mXn matrix, y is a mX1 and bhat is a nX1. I have already vectorized G but I can't get Sigma to work. My best try so far is the following.
Sigma=x.'*(((y-x*bhat).')*(y-x*bhat))*x;
G=x.'x;
I already realize why it is wrong, but I can't fix it. Thanks for the help in advance.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!