Re: Re: vector multiplication
- To: mathgroup at smc.vnet.net
- Subject: [mg26192] Re: [mg26182] Re: vector multiplication
- From: "Christopher J. Purcell" <purcell at drea.dnd.ca>
- Date: Thu, 30 Nov 2000 22:02:10 -0500 (EST)
- References: <8rjjdh$ofq@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Here is a slightly fancier version that adds another argument (like
the Version 4.0 Tr function).
I have no idea how to add the third argument.
Tr::usage="Tr[list] finds the trace of the matrix or tensor list.
Tr[list, f] finds a \
generalized trace, combining terms with f instead of Plus."
Tr[junk_List,func_:Plus]:=
Apply[func,
Map[junk[[Apply[Sequence,Table[#,{Length[Dimensions[junk]]}]]]]&,
Range[Min[Dimensions[junk]]]]]
>Tr[] is new in version 4. But this will work:
>
>tr[m_] := Plus @@ Table[m[[i, i]], {i, Min[Dimensions[m]]}]
>
>-- David
>
>
--
Dr. Christopher J. Purcell
GL/Trans
Defence Research Establishment Atlantic
9 Grove St., Dartmouth, NS Canada B2Y 3Z7
Tel: 902-426-3100-x389
Fax: 902-426-9654
E-mail: purcell at drea.dnd.ca