Karim Belabas on Wed, 15 Feb 2012 20:47:58 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: matconcat |
* Andreas Enge [2012-02-13 20:12]: > On Mon, Feb 13, 2012 at 08:01:55PM +0100, Karim Belabas wrote: > > Please provide "easy" building blocks of the required dimensions. :-) > > The "best" I can come up with is > > > > { > > matconcat([A, vector(2), vector(3); > > vectorv(2), B, matrix(2,3); > > vectorv(3), matrix(3,2), C]); > > } > > Sort of easy, but I agree it will become annoying with more and more diagonal > blocks. > > One could argue that this should already be handled by matdiagonal, > instead of creating a 3x3 matrix with matrix entries. > > Maybe two functions? matconcat for the cases where mathematicians draw > straight lines on a blackboard, and en extended matdiagonal (with a new > name, if need be) when they draw little boxes on a diagonal? I ended up modifying a little the original implementation, when dimensions don't match, choosing the "x = x*Identity" semantic for scalars 'x'. The algorithm uses 2 passes: we first determine block sizes, then extend submatrices by 0s until they match the block size. This covers all my original use cases, is reasonably coherent, not too hard to document; and straightforward to implement. The rigid alternative [ raise exception when anything doesn't match ] made matconcat() essentially useless: my examples could all be implemented using existing GP functions, with comparable readability. What makes matconcat() really useful in my scripts are the expanding zeroes. Please test and comment ! :-) K.B. -- Karim Belabas, IMB (UMR 5251) Tel: (+33) (0)5 40 00 26 17 Universite Bordeaux 1 Fax: (+33) (0)5 40 00 69 50 351, cours de la Liberation http://www.math.u-bordeaux1.fr/~belabas/ F-33405 Talence (France) http://pari.math.u-bordeaux1.fr/ [PARI/GP] `