[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Vectorizing a summation
From: |
Bård Skaflestad |
Subject: |
Re: Vectorizing a summation |
Date: |
Tue, 29 Jan 2013 16:11:01 +0100 |
On Tue, 2013-01-29 at 06:48 -0800, rdelgado wrote:
> The actual sum is:
>
> result = SUM(from i=1...MxN) SUM (from j=1...MxN) (Pi-Pj) * (Xi - Yi) * (Xj
> - Yj)
Aha, that changes things. The following probably won't reproduce the
exact results due to finite accuracy of floating-point calculations, but
it may nevertheless be sufficient for your needs.
x = reshape(X, [], 1);
y = reshape(Y, [], 1);
p = reshape(P, [], 1);
v = p.*sum(x - y) - sum(p .* (x - y));
result = sum(v .* (x - y));
Sincerely,
--
Bård Skaflestad <address@hidden>
- Vectorizing a summation, rdelgado, 2013/01/29
- Re: Vectorizing a summation, Michael Goffioul, 2013/01/29
- Re: Vectorizing a summation, Bård Skaflestad, 2013/01/29
- Re: Vectorizing a summation, rdelgado, 2013/01/29
- Re: Vectorizing a summation,
Bård Skaflestad <=
- Re: Vectorizing a summation, rdelgado, 2013/01/29
- Re: Vectorizing a summation, Bård Skaflestad, 2013/01/29
- Re: Vectorizing a summation, rdelgado, 2013/01/29
- Re: Vectorizing a summation, Bård Skaflestad, 2013/01/29
- Re: Vectorizing a summation, rdelgado, 2013/01/29
- Re: Vectorizing a summation, Jordi Gutiérrez Hermoso, 2013/01/29
- RE: Vectorizing a summation, Bård Skaflestad, 2013/01/29
- Re: Vectorizing a summation, Jordi Gutiérrez Hermoso, 2013/01/29