Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Indexed element treated as number?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80073] Re: [mg80055] Indexed element treated as number?
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 12 Aug 2007 07:09:45 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

Clear[a];

n = 100;
kList1 = Array[a, n];

{Im[a[1]], Im[a[37]]}

{Im(a(1)),Im(a(37))}

a /: Im[a[37]] = 0;

{Im[a[1]], Im[a[37]]}

{Im(a(1)),0}

a /: Im[a[_]] = 0;

{Im[a[1]], Im[a[37]]}

{0,0}


Bob Hanlon

---- Jung-Tsung Shen <jushen at gmail.com> wrote: 
> (* The following problem and alike have been asked before. I have
> searched extensively the archive of this forum but couldn't find a
> perfect solution. *)
> 
> 
> To get an array of length n, where n is large and post-given, one
> issues the command, for example,
> 
> n=100;
> kList1=Array[a, n];
> 
> but it seems that there are some limitations to this approach. For
> example, in cases that I know all of the elements are real, and would
> like to issue, say,
> 
> a[37]/:Im[a[37]]=0;
> 
> I get an error message saying
> "TagSet::sym: Argument a[37] at position 1 is expected to be a
> symbol." To declare the element to be explicitly zero sometimes speed
> up the computation.
> 
> For a list such as
> 
> kList2={k1, k2, k3, ..., k100};
> 
> there's no such limitations, but since the number of elements is
> large, and is post-given, I couldn't have this before hand.
> 
> Is there any solution(s) to this "problem"?
> 
> Thanks!
> 
> JT
> 



  • Prev by Date: Re: framed plots with two y axes scales
  • Next by Date: Re: Indexed element treated as number?
  • Previous by thread: Re: Indexed element treated as number?
  • Next by thread: Re: Indexed element treated as number?