Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorizing nested for loops
Date: Mon, 25 May 2009 18:06:02 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 11
Message-ID: <gvemma$s97$1@fred.mathworks.com>
References: <gvei09$3hm$1@fred.mathworks.com> <gveme8$cqh$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1243274762 28967 172.30.248.35 (25 May 2009 18:06:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 25 May 2009 18:06:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:542431


Sorry, actually you do not need bsxops, just do this:

> i = 2:nhx-1;
> j = 2:nhy-1;
> 
> Unew(i,j)= U(i,j)-dt*(P(i+1,j)-P(i-1,j))/(2*hx)...
>     +nu*dt*(1/(hx*hx)*(U(i+1,j)-2.*U(i,j)+U(i-1,j))...
>     +1/(hy*hy)*(U(i,j+1)-2.*U(i,j)+U(i,j-1)))...
>     -dt*U(i,j)./(hx).*(U(i,j)-U(i-1,j))...
>     -dt*V(i,j)./(2*hy).*(U(i,j+1)-U(i,j-1));
>