From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,d45251e6e639e463 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.227.67 with SMTP id ry3mr10262962pbc.8.1340648490809; Mon, 25 Jun 2012 11:21:30 -0700 (PDT) Path: l9ni19080pbj.0!nntp.google.com!news1.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: questions on using the array component iterator for 2012 Date: Mon, 25 Jun 2012 11:19:24 -0700 (PDT) Organization: http://groups.google.com Message-ID: <42e9adf6-5928-4742-b066-e3ec2b96e8cb@googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1340648490 9727 127.0.0.1 (25 Jun 2012 18:21:30 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 25 Jun 2012 18:21:30 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-06-25T11:19:24-07:00 List-Id: On Saturday, June 23, 2012 5:02:18 AM UTC-7, Nasser M. Abbasi wrote: > reference >=20 > But suppose I want to implement say a Jacobi relaxation > iteration to solve a 2D Laplace pde on that grid, which > is defined to update each element in the grid using >=20 > A(i) :=3D (1/4) ( A(i-1,j)+A(i+1,j)+A(i,j-1)+A(i,j+1) >=20 > where here 'i' is row index, and 'j' is column index. >=20 > http://en.wikipedia.org/wiki/Relaxation_%28iterative_method%29 That wouldn't even work, I think. My understanding of matrix math is limit= ed, but the Wikipedia article talks about repeatedly performing a *matrix* = assignment "phi :=3D phi*" where the elements of phi* are defined in terms = of the elements of phi. That is, you have to compute the entire matrix phi= * first, before reassigning back to the original matrix. The code you've w= ritten above will modify elements of A before they need to be used. You'd = need to do something like New_A(i,j) :=3D (1/4) ( A(i-1,j)+A(i+1,j)+A(i,j-1)+A(i,j+1) (you left the ",j" off the index of the left-hand side) and then A :=3D New_A after all elements are computed. At least that's how it looks to me. I don't really understand the math her= e, and maybe it's possible that the end results, if the loop is repeated en= ough times, would be the same even if you do modify elements of A before th= ey're used. But in any event, (1) an Ada array iterator isn't going to wor= k if more than one array is involved, and (2) I think array iterators reall= y are intended only for when you're focusing on each element one at a time.= If an operation on an array element requires that you look at other eleme= nts of the same array, then an array iterator isn't an appropriate construc= t to use. You'd want to make the indexes (in your case, the row and column= numbers) explicit so that readers will understand what you're doing. =20 -- Adam