Re: Package for Blockmatrices
- To: mathgroup at smc.vnet.net
- Subject: [mg7778] Re: Package for Blockmatrices
- From: Hans Steffani <hans.steffani at e-technik.tu-chemnitz.de>
- Date: Tue, 8 Jul 1997 22:40:58 -0400
- Sender: owner-wri-mathgroup at wolfram.com
>As you maybe saw, I am working on a package which handles >symbolik block matrices ie matrices which elements are >matrices themselfes. This leads to different behavior of >Dot and Transpose which are implemented in the package. >The package seems to work but I am not sure whether the >simplify functions are optimal concerning calculating time. >I hope to get some hints but also that the package may be >interesting for other mathematica users. I solved some errors (maybe is made some new ones) and changed the head of the both simplify functions. Hans Friedrich Steffani --snip--snap--begin of block.m--snip--snap-- (* block.m Handles the dot product of symbolik block matrix. This means that the elements of a matrix are not skalars but matrices. eg: (A11 A12) (B11 B12) (A11.B11+A12.B21 A11.B12+A12.B22) ( ) ( ) = ( ) (A21 A22) (B21 B22) (A21.B11+A22.B21 A21.B12+A22.B22) using the dot product on the right hand side instead of the normal times. Also Transpose[] has been enhaced because not only the blockmatrix itsself but also its elements have to be transposed. Todos: SymmetricSimplify[] and DotSimplify[] should become part of Simplify[]. An Inverse[] and Det[] have to be adapte to this purpose. Hans Friedrich Steffani Version 0.11 End fixed 0.2 Functions changed 0.21 Functions which are not needed are removed *) BeginPackage["Utilities`Block`"] DotSimplify::usage = "DotSimplify[expr, Scalars->{list of scalars}] replaces Dot[a,b] by Times[a,b] if a or b are in the list of scalars" Scalars::usage = "Scalars is an option for DotSimplify[expr, Scalars->{list of scalars}." SymmetricSimplify::usage = "SymmetricSimplify[expr, Symmetric->{list of symmetric values}] replaces Transpose[a] if a is in the list of symmetric values" Symmetrics::usage = "Symmetrics is an option for SymmetricSimplify which indicates symmetric matrices." Begin["`Private`"] Unprotect[Transpose] (* To Transpose the matrix all Elements get transposed and the matrix itself too *) Transpose[m_?MatrixQ] := Transpose[Map[Transpose, m,{2}], {2,1}] Transpose[m_?NumberQ] := m Transpose[Transpose[expr_]] := expr Protect[Transpose] Unprotect[Dot] Dot[a_?MatrixQ, b_?MatrixQ] := Inner[Dot, a, b, Plus] Dot[a_?NumberQ, b_] := Times[a, b] Dot[a_, b_?NumberQ] := Times[a, b] Protect[Dot] DotSimplify[expr_, opt:Scalars->theScalars_List] := Module[{}, Unprotect[mydot]; Clear[mydot]; mydot[m1_/; (MemberQ[theScalars,m1]), m2_ ] := Times[m1,m2] ; mydot[m1_, m2_/; (MemberQ[theScalars,m2]) ] := Times[m1,m2] ; SetAttributes[ mydot,{Flat,OneIdentity} ]; Protect[mydot]; mytranspose[ m_/; (MemberQ[theScalars,m]) ] := m; expr/.{Dot->mydot,Transpose->mytranspose}/.{mydot->Dot,mytranspose->Transpose} ] SymmetricSimplify[expr_, opt:Symmetrics->theSymmetrics_List ] := Module[{}, Clear[mytranspose]; mytranspose[ m_/;(MemberQ[ theSymmetrics, m]) ] := m; expr/.{Transpose->mytranspose}/.{mytranspose->Transpose} ] Unprotect[Simplify] Protect[Simplify] End[] (* Private *) EndPackage[] --snip--snap--end of block.m--snip--snap-- -- Hans Friedrich Steffani Institut fuer Elektrische Maschinen und Antriebe, TU Chemnitz-Zwickau mailto:hans.steffani at e-technik.tu-chemnitz.de http://www.tu-chemnitz.de/~hfst/