comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: matrix manipulation
Date: Tue, 15 Nov 2016 09:54:24 -0800 (PST)
Date: 2016-11-15T09:54:24-08:00	[thread overview]
Message-ID: <4a3af35f-9830-42cd-b324-271e174dc0f1@googlegroups.com> (raw)
In-Reply-To: <055e3e13-93dc-4653-bc20-e09bd6c53bce@googlegroups.com>

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.


  reply	other threads:[~2016-11-15 17:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-12 18:16 matrix manipulation hnptz
2016-11-12 19:12 ` Jacob Sparre Andersen
2016-11-12 23:30 ` Stephen Leake
2016-11-14 17:39   ` hnptz
2016-11-15 17:54     ` Stephen Leake [this message]
2016-11-15 18:57 ` Robert Eachus
  -- strict thread matches above, loose matches on Subject: below --
2019-04-27 14:50 hnptz
2019-04-27 15:05 ` mockturtle
2019-04-27 15:21 ` hnptz
2019-04-27 16:37   ` J-P. Rosen
2019-04-27 16:58     ` mockturtle
2019-04-27 22:45 ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox