From: Marios Karaoulis on
On May 19, 1:31 pm, "Matt Fig" <spama...(a)yahoo.com> wrote:
> 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!

Thanks man, with your advice I managed to reduced speed time at least
5 times.

Bruno Luong solution is not working for me.

it says inner matrix dimension must agree.
a=1X8
b=1X8
c=8X8
From: Bruno Luong on
Marios Karaoulis <marios.karaoulis(a)gmail.com> wrote in message <b7e95dac-bc98-452c-8fde-c22f2c64bfaf(a)a39g2000prb.googlegroups.com>...

>
> Bruno Luong solution is not working for me.

Really? Here is my test

>> a=rand(1,8)

a =

Columns 1 through 7

0.8147 0.9058 0.1270 0.9134 0.6324 0.0975 0.2785

Column 8

0.5469

>> b=rand(1,8)

b =

Columns 1 through 7

0.9575 0.9649 0.1576 0.9706 0.9572 0.4854 0.8003

Column 8

0.1419

>> c=rand(8,8)

c =

Columns 1 through 7

0.4218 0.6787 0.2769 0.4387 0.7094 0.9597 0.8909
0.9157 0.7577 0.0462 0.3816 0.7547 0.3404 0.9593
0.7922 0.7431 0.0971 0.7655 0.2760 0.5853 0.5472
0.9595 0.3922 0.8235 0.7952 0.6797 0.2238 0.1386
0.6557 0.6555 0.6948 0.1869 0.6551 0.7513 0.1493
0.0357 0.1712 0.3171 0.4898 0.1626 0.2551 0.2575
0.8491 0.7060 0.9502 0.4456 0.1190 0.5060 0.8407
0.9340 0.0318 0.0344 0.6463 0.4984 0.6991 0.2543

Column 8

0.8143
0.2435
0.9293
0.3500
0.1966
0.2511
0.6160
0.4733

>> S2 = (a'*b).*c; % Matt's solution
S2 = sum(S2(:))

S2 =

13.6153

>> a(:).'*c*b(:) % Bruno's solution

ans =

13.6153

% Bruno
From: Matt Fig on
Bruno's solution should work, and is actually to be preferred. It is the solution I was working towards when I ran out of time earlier. Are you sure about your test data?
First  |  Prev  | 
Pages: 1 2
Prev: imrotatemex
Next: naming a .NET component