MathGroup Archive 2001

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

Search the Archive

Re: List Manipulation

  • To: mathgroup at
  • Subject: [mg31547] Re: [mg31538] List Manipulation
  • From: Tomas Garza <tgarza01 at>
  • Date: Sat, 10 Nov 2001 01:19:34 -0500 (EST)
  • Sender: owner-wri-mathgroup at

Recall that  "Sign[x] gives -1, 0 or 1 depending on whether x is negative,
zero, or positive." (See the on-line Help browser). If

listA = {{A, {0, 0, 0, a}}, {B, {b, 0, 0, d}},
   {C, {-a, -b, 0, 0}}, {D, {c, 0, 0, -c}}};

 there are many possibilities. Consider the following two (here a, b, c, d
have not been assigned numerical values; once they have you'll get the
appropriate -1, 0, or 1) :

({#1[[1]], Sign[#1[[2]]]} & ) /@ listA
{{A, {0, 0, 0, Sign[a]}}, {B, {Sign[b], 0, 0, Sign[d]}},
  {C, {-Sign[a], -Sign[b], 0, 0}},
  {D, {Sign[c], 0, 0, -Sign[c]}}}

listA /. {x_, y_List} -> {x, Sign[y]}
{{A, {0, 0, 0, Sign[a]}}, {B, {Sign[b], 0, 0, Sign[d]}},
  {C, {-Sign[a], -Sign[b], 0, 0}},
  {D, {Sign[c], 0, 0, -Sign[c]}}}

These work because Sign has the attribute of listability (q.v.) and so it
operates on each of the elements of the inner list.

Tomas Garza
Mexico City

----- Original Message -----
From: "Jonathan Woodward" <woodward at>
To: mathgroup at
Subject: [mg31547] [mg31538] List Manipulation

> I am a relatively new user to Mathematica with virutally no
> programming experience and need help with a problem:
> Given the following hypothetical eigensystem, a "list of lists" which
> has the eigenvalues (A,B,C,D) associated with their corresponding
> eigenvectors ({0,0,0,a},{b,0,0,d},{-a,-b,0,0},{c,0,0,-c}):
> {{A,{0,0,0,a}},{B,{b,0,0,d}},{C,{-a,-b,0,0}},{D,{c,0,0,-c}}}
> where the list contains zeros, symbolic expressions, and numbers.
> The actual system I have is the eigensystem of a 32x32 symbolic matrix
> where the vector components seem to take up hundreds of pages and
> are therefore almost useless to me.  However, I am interested in the
> position of the zero and nonzero components only, not their actual
> values.
> So what I want to do is transform the list into another more
> useful list in the following way:
> I do not want to change the eigenvalues but want to convert all
> eigenvector
> components in such a way that I have a list of zeros, ones, and
> negative ones.
> In other words, divide each eigenvector component by its absolute
> value, except for the zeros, to create a new list that might now look
> like:
> {{A,{0,0,0,1}},{B,{1,0,0,1}},{C,{-1,-1,0,0}},{D,{1,0,0,-1}}}
> This way I can greatly simplify my problem while keeping the position
> of the
> zero and nonzero elements of the components unchanged.
> How would I write a code in Mathematica to accomplish this?  In
> particular,
> how would do I tell the program to scan through this list, doing
> nothing
> to the eigenvalues, but look through the eigenvectors, check to see if
> they
> are nonzero (if zero, do nothing) and divide each nonzero component by
> its
> absolute value, and return a new list.  I don't want to break the list
> apart
> and operate just on the vector components themselves because I want to
> preserve the eigenvalue-eigenvector association.  Also, I need to be
> able to tell
> the program that symbols of the type {x} are positive and {-x} are
> negative
> otherwise I might have a list returned like:
{{A,{0,0,0,a/Abs[a]}},{B,{b/Abs[b],0,0,d/Abs[d]}},{C,{-a/Abs[a],-b/Abs[b] ,0,
> which is not simplified to what I need.
> Any help would be greatly appreciated.
> Thanks
> Jonathan Woodward

  • Prev by Date: Re: Storing Data into Excel - Pls Help ...
  • Next by Date: Re: Re: Re: Limit question
  • Previous by thread: Re: List Manipulation
  • Next by thread: Re: List Manipulation