From help-request at octave dot org Fri Feb 11 08:48:00 2005 Subject: Re: Access the neighbors of an element From: Francesco Potorti` To: Jörg Sommer CC: help at octave dot com, help@octave.org, Przemek Klosowski Date: Fri, 11 Feb 2005 15:50:29 +0100 >Over the time, the matrix changes only at one position. By hand it is >much easier to calculate the passage of the energie of one matrix to the >other, than calculate the whole energie again. The transit is in O(1), >the energie is in O(n^2). > >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 increase n enough, you will find the n where the O(1) time solution is faster. >> 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. -- Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111) ISTI - Area della ricerca CNR Fax: +39 050 313 8091 via G. Moruzzi 1, I-56124 Pisa Email: Potorti at isti dot cnr dot it Web: http://fly.isti.cnr.it/ Key: fly.isti.cnr.it/public.key ------------------------------------------------------------- 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 -------------------------------------------------------------