MathGroup Archive 2006

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

Search the Archive

Re: creating a symbolic square symmetric matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66326] Re: creating a symbolic square symmetric matrix
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Tue, 9 May 2006 03:59:37 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <e3pege$ifq$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

ravi wrote:
> Hi,
> First, I created a square matrix with the following command :
> n=4;
> mat=Table[Subscript[a,i, j],{i,n},{j,n}]
> In the same style, I would like to create a symmetric matric where all
> a[i, j] is replaced by a[j,i] for i>j. For i<=j, the coefficients
> remain in place.
> I tried to use the replace command :
> Replace[mat,Subscript[a,i,j]->Subscript[a,j,i]]
> This just interchanged the elements. I want this replacement only for
> the lower or upper triangular matrix elements.
> Would appreciate tips of doing a conditional substitution.
> /ravi
> 
Hi Ravi,

Conditions can be added by *Condition* (/; in the example) [1] as in the 
following

In[1]:=
With[{n=4},
m=Table[Subscript[a,i,j],{i,n},{j,n}]]

Out[1]//OutputForm=
a      a      a      a
  1,1    1,2    1,3    1,4

a      a      a      a
  2,1    2,2    2,3    2,4

a      a      a      a
  3,1    3,2    3,3    3,4

a      a      a      a
  4,1    4,2    4,3    4,4

In[2]:=
m /. Subscript[a, i_, j_] /;
     i > j -> Subscript[a, j, i]

Out[2]//OutputForm=
a      a      a      a
  1,1    1,2    1,3    1,4

a      a      a      a
  1,2    2,2    2,3    2,4

a      a      a      a
  1,3    2,3    3,3    3,4

a      a      a      a
  1,4    2,4    3,4    4,4

HTH,
Jean-Marc


  • Prev by Date: Re: 3D surface plotting
  • Next by Date: Re: "In progress" saving of data collected using Reap/Sow
  • Previous by thread: creating a symbolic square symmetric matrix
  • Next by thread: Re: creating a symbolic square symmetric matrix