Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Nonatomic expression ? in Append command

1,098 views
Skip to first unread message

Takayuki MAKINO

unread,
Feb 14, 2002, 2:15:00 AM2/14/02
to
bonjour

I am very happy to meet you all. My name is Takayuki. It is my great
pleasure to know the existense of such beautiful community. I would like
to perform the loop calculation by writing the following code in
Mathematica. Then, the result of calculation should be stored in some
lists, assuming the name of list is "omegaAlist". If one performs that
code, the error message will be output. The contents of which is the
following:

(1)「Append::"normal": "Nonatomic expression expected at position 1
in Append[omegaAlist, 0.007]."」

(2)「$RecursionLimit::"reclim": "Recursion depth of \!\(256
\) exceeded."」

I do not know how to work around this problem. Please help me to
eliminate this obstacle, if there are experts who are familiar with
these kinds of things.!!!

------------------------------------------------

Clear[et1,omegaAlist]
For[r =0, r <= 1, r++

et1 = 3.444 + r*0.001

omegaAlist = Append[omegaAlist, N[et1]];
]
omegaAlist = Delete[omegaAlist, 1];


Erk Jensen

unread,
Feb 15, 2002, 2:50:18 AM2/15/02
to

Salut,

I find that your loop is a little weird, since r is increased by one, and your
test is r<=1, but if I increase it a little bit to see it at work, I get a
result that you might want, just by adding an initialization of omegaAlist:

Clear[et1, omegaAlist]
omegaAlist = {};
For[r = 0, r <= 10, r++,
et1 = 3.444 + r 0.001;

omegaAlist = Append[omegaAlist, N[et1]]; ]

bonne journ�e
-erk-
--
Dr.-Ing. Erk JENSEN mailto:Erk.J...@cern.ch
CERN PS/RF L19510 http://cern.ch/Erk.Jensen
CH-1211 Geneva 23 Tel.: +41 22 76 74298
Switzerland Fax.: +41 22 76 78510

Jens-Peer Kuska

unread,
Feb 15, 2002, 2:59:06 AM2/15/02
to
Hi,


you can only append a *element* to a list. Since you Clear[omegaAList]
it has no value you need:

Clear[et1, omegaAlist]

omegaAlist = {};

For[r = 0, r <= 1, r++ , et1 = 3.444 + r*0.001;

omegaAlist = Append[omegaAlist, N[et1]];
]
omegaAlist = Delete[omegaAlist, 1];

Avoid explicit loops with For[] and Append[]/AppendTo[]

Regards
Jens

BobH...@aol.com

unread,
Feb 15, 2002, 3:01:58 AM2/15/02
to

In a message dated 2/14/02 4:09:03 AM, tma...@spectro.ujf-grenoble.fr writes:

>I would like
> to perform the loop calculation by writing the following code in
> Mathematica. Then, the result of calculation should be stored in some
> lists, assuming the name of list is "omegaAlist". If one performs that
> code, the error message will be output. The contents of which is the
> following:
>

> (1)ÅuAppend::"normal": "Nonatomic expression expected at position 1
> in Append[omegaAlist, 0.007]."Åv
>
> (2)Åu$RecursionLimit::"reclim": "Recursion depth of \!\(256
> \) exceeded."Åv


>
> I do not know how to work around this problem. Please help me to
> eliminate this obstacle, if there are experts who are familiar with
> these kinds of things.!!!
>
> ------------------------------------------------
>
> Clear[et1,omegaAlist]
> For[r =0, r <= 1, r++
>
> et1 = 3.444 + r*0.001
>
> omegaAlist = Append[omegaAlist, N[et1]];
> ]
> omegaAlist = Delete[omegaAlist, 1];
>

Clear[et1,omegaAlist];

Since you cleared omegaAlist, it is just a Symbol (atomic)
and not a List to which elements can be appended.
You need to initialize it to an empty list.

For[omegaAlist={}; r=0, r<=3, r++ ,

et1=3.444+r*0.001;

omegaAlist=Append[omegaAlist, et1]];
omegaAlist=Delete[omegaAlist, 1]

{3.445, 3.446, 3.447}

Another approach would be

omegaAlist=Table[3.444+r*0.001, {r, 3}]

{3.445, 3.446, 3.447}


Bob Hanlon
Chantilly, VA USA

Avraham Shinnar

unread,
Feb 15, 2002, 3:05:50 AM2/15/02
to
you are missing some puctuation. Also, you need to first initialize
omegaAlist to an empty list:

Clear[et1, omegaAlist];
omegaAlist = {};
For[r = 0, r <= 1, r++,

et1 = 3.444 + r*0.001;

omegaAlist = Append[omegaAlist, N[et1]];
]

Print[omegaAlist];


omegaAlist = Delete[omegaAlist, 1];

However, a much better approach is to use list-based programming:

omegaAlist = 3.444 + # 0.001 & /@ Range[0, 1]

This approafch allows you to make changes to basically the same variables as
in your For loop. A less general way, would be:

omegaAlist = NestList[# + .001 &, 3.444, 1]

-- Avraham

"Takayuki MAKINO" <tma...@spectro.ujf-grenoble.fr> wrote in message
news:a4fo5k$j55$1...@smc.vnet.net...

Tomas Garza

unread,
Feb 15, 2002, 3:15:35 AM2/15/02
to
I suggest you devote some time to learning functional programming, which is
one of the great beauties of Mathematica, and forget all about loops and
procedural programming.

Anyway, it is not clear to me what is it you're trying to achieve in your
routine below. To start with, since no initial value is assigned to
omegaAlist, it is clear that you can't Append anything to it in the first
loop. This is why you get the message.

Secondly, surely you are aware that r++ increases the value of r by 1,
returning the old value of r. Then you cannot go further than the first
loop, since the test r<=1 gives False immediately after the first loop.

Tomas Garza
Mexico City

0 new messages