From: Marios Karaoulis on
I need some advice

i have this loop and I want it to vectrorize it.


sum=0;
for i=1:8
for j=1:8
sum=sum+a(i)*b(j)*c(i,j);
end
end

How can I do it
From: Walter Roberson on
Marios Karaoulis wrote:
> I need some advice
>
> i have this loop and I want it to vectrorize it.
>
>
> sum=0;
> for i=1:8
> for j=1:8
> sum=sum+a(i)*b(j)*c(i,j);
> end
> end
>
> How can I do it

Start by pulling constant factors out. a(i) is independant of j, so if you
calculate sum b(j)*c(i,j) over j and multiply that sum by a(i) you will have a
partial speedup. After you have coded for that, look and see what else does
not need to be calculated over and over again.
From: Matt Fig on
Assuming a and b are 1-by-N, and c is N-by-N,

S2 = (a'*b).*c;
S2 = sum(S2(:))

Also, I wouldn't use the built-in function name 'sum' as a variable if I were you!
From: Bruno Luong on

> How can I do it

a(:).'*c*b(:)

Bruno
From: Marios Karaoulis on
Thank you all, I am trying in them and I will check.
 |  Next  |  Last
Pages: 1 2
Prev: imrotatemex
Next: naming a .NET component