```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Order of operations in a vectorized function
Date: Tue, 3 Aug 2010 19:58:04 +0000 (UTC)
Organization: Technion
Lines: 19
Message-ID: <i39scc\$h7k\$1@fred.mathworks.com>
References: <i39kf9\$bt5\$1@fred.mathworks.com> <i39pvi\$7g8\$1@fred.mathworks.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1280865484 17652 172.30.248.38 (3 Aug 2010 19:58:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 3 Aug 2010 19:58:04 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:658723

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i39pvi\$7g8\$1@fred.mathworks.com>...
> - - - - - - - - - - -
>   In the "vectorized" form you have written, it doesn't look like Gauss-Seidel iteration to me.  For each element of grid, matlab will use the old values in grid for all its computations.  It accomplishes this by temporarily storing two copies of the grid matrix in separate buffers, the old values and the new values.  The computation on the right takes from the old value matrix and puts the results into the new value matrix.  Imagine that you wrote "temp_grid" on the left side and after the computation was finished for all elements you then wrote grid = temp_grid to copy the new results back into grid.  That would be equivalent to the vectorized action.
>
>   Note that this is general different from the results you would get if you put it in nested for-loops like this:
>
>  for i1 = 1:n
>   for i2 = 1:n
>    grid(i1,i2) = the above expression in grid(i1,i2) ;
>   end
>  end
>
>   A lot of beginners in matlab make the mistake of not distinguishing between these two different ways of proceeding.
>
> Roger Stafford

Roger, thank you.
So, it seems there's no way of avoiding using loops in this case? "Vectorization" is only good when all the data are on the same 'time' level in the iteration, and if I specifically want to use the updated values, I need to loop?
In general though, using .* and so on is substantially faster then using a loop for the same calculation?
```