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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.29.16 with SMTP id d16mr5353311iod.21.1479232464873; Tue, 15 Nov 2016 09:54:24 -0800 (PST) X-Received: by 10.157.37.247 with SMTP id q110mr1704374ota.5.1479232464835; Tue, 15 Nov 2016 09:54:24 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!w132no79627ita.0!news-out.google.com!x12ni1179ita.0!nntp.google.com!o1no81462ito.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 15 Nov 2016 09:54:24 -0800 (PST) In-Reply-To: <055e3e13-93dc-4653-bc20-e09bd6c53bce@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=76.218.37.33; posting-account=W2gdXQoAAADxIuhBWhPFjUps3wUp4RhQ NNTP-Posting-Host: 76.218.37.33 References: <055e3e13-93dc-4653-bc20-e09bd6c53bce@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4a3af35f-9830-42cd-b324-271e174dc0f1@googlegroups.com> Subject: Re: matrix manipulation From: Stephen Leake Injection-Date: Tue, 15 Nov 2016 17:54:24 +0000 Content-Type: text/plain; charset=UTF-8 Xref: news.eternal-september.org comp.lang.ada:32326 Date: 2016-11-15T09:54:24-08:00 List-Id: On Monday, November 14, 2016 at 11:39:56 AM UTC-6, hn...@yahoo.de wrote: > On Sunday, November 13, 2016 at 12:30:16 AM UTC+1, Stephen Leake wrote: > > On Saturday, November 12, 2016 at 12:16:47 PM UTC-6, hn...@yahoo.de wrote: > > > What is an elegant way to program exchange of columns in a matrix. > > > Application: > > > C is a matrix. Cj be the j-th column of C. > > > Sort C1,C2, ..., Cn in non increasing order with respect to their first component. > > > I tried and ended up in a very messy program, as I had to sort the first components first, remember their new index and then reconstruct the matrix. > > > > declare the matrix as an array of columns: > > > > type Column is array (1 .. 10) of float; > > type Matrix is array (1 .. 10) of Column; > > > > A : Matrix := ...; > > Tmp : Column; > > > > Tmp := A (2); > > A (2) := A (1); > > A (1) := Tmp; > > How to access a single element of matrix A ? Is it A(1)(1) ? Yes. > I think, I cannot use it as a Matrix anymore applying build in > Ada-procedures, like for solving equations or transposing the matrix. I > would have to transform it into a 2-dimensional array, right ? I guess you mean the type Ada.Numerics.Generic_Complex_Arrays.Complex_Matrix, or something similar. It helps to have _all_ of the requirements at hand when designing a solution :) You have two choices here; write code two swap two rows of a 2D array, or copy the 2D array to an array of arrays, swap, and copy back. You'd have to measure to be sure which is more efficient, and the result will depend on matrix size. For an initial design, it is best to go with code that is easiest to understand and implement; get it right first, then measure it, then improve only if necessary.