[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Access the neighbors of an element
From: |
Joerg Sommer |
Subject: |
Re: Access the neighbors of an element |
Date: |
Sat, 12 Feb 2005 00:55:26 +0000 (UTC) |
User-agent: |
slrn/0.9.8.0 (Linux) |
Francesco Potorti` <address@hidden> wrote:
>>My idea was to do the same in octave, but it doesn't work. It's faster to
>>compare 800 elements than find and access 4 elements.
>
> In fact, it works, as soon as you remember that O(1) and O(n^2) need at
> least a multiplicative constant in order to produce times. If you
:) Yes, you are right. But I wonder, that the constant before O(1) is so
greate, that it blast O(n^2) (with n=20) away.
>>> If that's your case, then you can do it the way I said, using terms of the
>>> form
>>> (X(m,n) == X(m-1,n)).
>>
>>But n and m are chosen randomly and I don't know if m+1, m-1, n-1, n+1
>>exist.
>
> Create a matrix with guard (first and last) columns and rows, which are
> not used for computations, but only to be sure that m+1, m-1, n+1, n-1
> all exist. Fille them with values that do not change the results of
> your computations. For example, you can use "*" instead of "==" when
> computing the energy and set the guard values to 0, so they do not
> interfere.
Super idea! Really great idea. I'm enthused! I've changed my code this
way and it is 33% faster than the old version. But now it is evident,
that the code can not become better. Two lines are the end. ;-)
neighbor = [-(n+2), n+2, -1, 1] + pos(t);
Y_energ = X_energ + 2 * sum( X(pos(t)) .* X(neighbor) );
Is it possible to tell octave it should use integer data types? I don't
need floating point operations.
Good night, Joerg.
--
"UNIX was not designed to stop people from doing stupid things, because
that would also stop them from doing clever things."
-- Doug Gwyn
-------------------------------------------------------------
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
-------------------------------------------------------------
- Access the neighbors of an element, Joerg Sommer, 2005/02/09
- Re: Access the neighbors of an element, Mike Miller, 2005/02/09
- Re: Access the neighbors of an element, Francesco Potorti`, 2005/02/10
- Message not available
- Re: Access the neighbors of an element, Jörg Sommer, 2005/02/10
- Re: Access the neighbors of an element, Francesco Potorti`, 2005/02/11
- Re: Access the neighbors of an element,
Joerg Sommer <=
- Re: Access the neighbors of an element, John W. Eaton, 2005/02/11
- Data types (was: Re: Access the neighbors of an element), Joerg Sommer, 2005/02/12
- Data types (was: Re: Access the neighbors of an element), John W. Eaton, 2005/02/12
- Re: Data types (was: Re: Access the neighbors of an element), Paul Kienzle, 2005/02/12
- Re: Data types (was: Re: Access the neighbors of an element), Paul Kienzle, 2005/02/12
- Re: Access the neighbors of an element, Joerg Sommer, 2005/02/12