MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Chain Matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96499] Re: Chain Matrix
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 14 Feb 2009 04:14:55 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <gn3bvk$q50$1@smc.vnet.net>

In article <gn3bvk$q50$1 at smc.vnet.net>,
 Antonio Carlos Siqueira <antoniocslima71 at gmail.com> wrote:

> I have a matrix in which all the elements are function of a scalar h,
> Say q[h]={{q1,q2},{q3,q4}} and what I need is to create a chain matrix
> so I can obtain the dot product of several q[h]. For instance, if  h=
> {h1,h2,h3}
> I can create a large matrix with
> m=Map[q,h]
> Then I do
> Dot[m[[1]],m[[2],m[[3] ]
> 
> The problem is that there are cases where the Length[h] may reach a
> few hundreds and I do not want to write Dot[m[[1]], ..., m[[200]] ]
> So  I have a somewhat trivial question:
>  Is there any way I can do this automatically? I mean how can I create
> a function to create an equivalent matrix from a chain of matrices?
> I tried some solutions with thread and fold, but I did not get
> anywhere, any thoughts are appreciated.

If your matrices are stored within a list, as suggested by the syntax 
m[[1]], etc., your could use either 

    Dot[Sequence @@ m]

or 

    Fold[#1.#2 &, First[m], Rest[m]]

for instance.

In[1]:= m = Array[#, {2, 2}] & /@ {h1, h2, h3}

Out[1]= {{{h1[1, 1], h1[1, 2]}, {h1[2, 1], h1[2, 2]}}, {{h2[1, 1], 
   h2[1, 2]}, {h2[2, 1], h2[2, 2]}}, {{h3[1, 1], h3[1, 2]}, {h3[2, 1],
    h3[2, 2]}}}

In[2]:= Dot[m[[1]], m[[2]], m[[3]]]

Out[2]= {{(h1[1, 1] h2[1, 1] + h1[1, 2] h2[2, 1]) h3[1, 
     1] + (h1[1, 1] h2[1, 2] + h1[1, 2] h2[2, 2]) h3[2, 
     1], (h1[1, 1] h2[1, 1] + h1[1, 2] h2[2, 1]) h3[1, 
     2] + (h1[1, 1] h2[1, 2] + h1[1, 2] h2[2, 2]) h3[2, 
     2]}, {(h1[2, 1] h2[1, 1] + h1[2, 2] h2[2, 1]) h3[1, 
     1] + (h1[2, 1] h2[1, 2] + h1[2, 2] h2[2, 2]) h3[2, 
     1], (h1[2, 1] h2[1, 1] + h1[2, 2] h2[2, 1]) h3[1, 
     2] + (h1[2, 1] h2[1, 2] + h1[2, 2] h2[2, 2]) h3[2, 2]}}

In[3]:= Dot[Sequence @@ m]

Out[3]= {{(h1[1, 1] h2[1, 1] + h1[1, 2] h2[2, 1]) h3[1, 
     1] + (h1[1, 1] h2[1, 2] + h1[1, 2] h2[2, 2]) h3[2, 
     1], (h1[1, 1] h2[1, 1] + h1[1, 2] h2[2, 1]) h3[1, 
     2] + (h1[1, 1] h2[1, 2] + h1[1, 2] h2[2, 2]) h3[2, 
     2]}, {(h1[2, 1] h2[1, 1] + h1[2, 2] h2[2, 1]) h3[1, 
     1] + (h1[2, 1] h2[1, 2] + h1[2, 2] h2[2, 2]) h3[2, 
     1], (h1[2, 1] h2[1, 1] + h1[2, 2] h2[2, 1]) h3[1, 
     2] + (h1[2, 1] h2[1, 2] + h1[2, 2] h2[2, 2]) h3[2, 2]}}

In[4]:= % === %%

Out[4]= True

In[5]:= Fold[#1.#2 &, First[m], Rest[m]]

Out[5]= {{(h1[1, 1] h2[1, 1] + h1[1, 2] h2[2, 1]) h3[1, 
     1] + (h1[1, 1] h2[1, 2] + h1[1, 2] h2[2, 2]) h3[2, 
     1], (h1[1, 1] h2[1, 1] + h1[1, 2] h2[2, 1]) h3[1, 
     2] + (h1[1, 1] h2[1, 2] + h1[1, 2] h2[2, 2]) h3[2, 
     2]}, {(h1[2, 1] h2[1, 1] + h1[2, 2] h2[2, 1]) h3[1, 
     1] + (h1[2, 1] h2[1, 2] + h1[2, 2] h2[2, 2]) h3[2, 
     1], (h1[2, 1] h2[1, 1] + h1[2, 2] h2[2, 1]) h3[1, 
     2] + (h1[2, 1] h2[1, 2] + h1[2, 2] h2[2, 2]) h3[2, 2]}}

In[6]:= % === %%%

Out[6]= True

Regards,
--Jean-Marc


  • Prev by Date: Re: Shortest Path Problem
  • Next by Date: Re: Re: Re: Log[x]//TraditionalForm
  • Previous by thread: Re: Chain Matrix
  • Next by thread: Re: Chain Matrix