Re: Simplify formula for iterative programming
- From: Martin Eisenberg <martin.eisenberg@xxxxxxx>
- Date: 3 Jun 2005 14:27:38 GMT
Stef wrote:
> I am looking for the simplification of a formula to improve the
> calculation speed of my program. Therefore I want to simplify
> the following formula:
>
> H = Si (Sj ( sqrt [ (Ai - Aj)² + (Bi - Bj)² ] ) )
>
> where:
> A, B = two vectors (with numerical data) of length n
> Si = summation over i (= 0 to n)
> Sj = summation over j (= 0 to n)
>
> n is not fixed, but it changes with every run for my program.
> Therefore for I am looking for a simplication of H in order to
> calculate it when my A and B get extendend by 1 element (n = n +
> 1).
The standard deviation formula you mentioned is very simply derived
by expanding the binomial formula and summing terms. No similar thing
can be done in your case since the sqrt is inside the sums. So I
think the best you can do is split the sums as given at index n-1,
then note that the extension sums are the same except for length and
that their difference vanishes:
H[n]
= H[n-1] + sum{i=0..n-1, sqrt((A[i]-A[n])^2 + (B[i]-B[n])^2)}
+ sum{j=0..n , sqrt((A[n]-A[j])^2 + (B[n]-B[j])^2)}
= H[n-1] + 2 * sum{i=0..n-1, sqrt((A[i]-A[n])^2 + (B[i]-B[n])^2)}
The recursion starts out with H[0] = 0. Of course, more is possible
if you can elide the sqrt from the definition of H and reformulate
the rest of your algorithm accordingly.
--
Quidquid latine dictum sit, altum viditur.
.
- References:
- Simplify formula for iterative programming
- From: stefaan . lhermitte
- Simplify formula for iterative programming
- Prev by Date: Re: java
- Next by Date: Re: Simplify formula for iterative programming
- Previous by thread: Simplify formula for iterative programming
- Next by thread: Re: Simplify formula for iterative programming
- Index(es):
Relevant Pages
|