Re: Product command with matrices
- To: mathgroup at smc.vnet.net
- Subject: [mg87922] Re: Product command with matrices
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sat, 19 Apr 2008 23:53:36 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <fu9ft7$ce2$1@smc.vnet.net>
J Davis wrote: > I want to define a matrix valued function such as the following (in > LaTeX lingo): > > $$ > X(0)=Id, > X(n)=\prod_{i=0}^{n-1} (Id + f[i] A) > $$ > > where A and f have already been defined and Id is the identity matrix > of appropriate size. > > I tried the following: > > Id=IdentityMatrix[2]; > Phi[0]:=Id; > Phi[n_]:= Product[Id + f[i] A,{i,0,n-1}] > > However, Phi[3] and (Id+f[2]A).(Id+f[1]A).(Id+f[0]A) do not agree. The following will do the recursion and correctly handle the *matrix* product (which Product[] does not do). Fold[(Id + f[#2] A).#1 &, Id + f[0] A, Range[n - 1]] Here is an example of a complete definition: Id = IdentityMatrix[2]; phi[0] := Id; phi[n_] := Fold[(Id + f[#2] A).#1 &, Id + f[0] A, Range[n - 1]] phi[3] % == (Id + f[2] A).(Id + f[1] A).(Id + f[0] A) // Simplify {{A (A (1 + A f[0]) f[1] + A f[0] (1 + A f[1])) f[ 2] + (A^2 f[0] f[1] + (1 + A f[0]) (1 + A f[1])) (1 + A f[2]), A (A^2 f[0] f[1] + (1 + A f[0]) (1 + A f[1])) f[ 2] + (A (1 + A f[0]) f[1] + A f[0] (1 + A f[1])) (1 + A f[2])}, {A (A^2 f[0] f[1] + (1 + A f[0]) (1 + A f[1])) f[ 2] + (A (1 + A f[0]) f[1] + A f[0] (1 + A f[1])) (1 + A f[2]), A (A (1 + A f[0]) f[1] + A f[0] (1 + A f[1])) f[ 2] + (A^2 f[0] f[1] + (1 + A f[0]) (1 + A f[1])) (1 + A f[2])}} True Regards, -- Jean-Marc