How do I vectorize the following the summation?
Show older comments
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.
Accepted Answer
More Answers (0)
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!