help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help on calculating sum of combinations


From: Mike Miller
Subject: Re: help on calculating sum of combinations
Date: Thu, 9 Oct 2003 13:26:51 -0500 (CDT)

On Wed, 8 Oct 2003, Miquel Cabanas wrote:

> >       a2=2*3+2*4+2*5
>
> that's easy too, take the first element of A, i.e. "A(1)", and
> multiply it element-by-element, i.e. ".*", by all remaining elements
> of A, that is from A(2) to A(length(A)), i.e. "A(2:length(A))"

For the sum of products of all pairs of elements of column vector A, you
can do this:

a2 = sum(tril(A*A',-1))

If A is a row vector, you have to do this instead:

a2 = sum(tril(A'*A,-1))

Mike



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]