The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: problem with append
Replies: 9   Last Post: Jan 22, 2013 11:18 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
yehuda ben-shimol

Posts: 302
Registered: 2/11/05
Re: problem with append
Posted: Jan 21, 2013 12:07 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

There are some errors here
1. The function name is AppendTo (with capital T) - Mathematica is case
2. Even this would not help, since r={} in the body of AppendTo refers to
the return value of the assignment rather than to rr
Combining 1 and 2 above results with the immediate correction

rr = {};
For[a = 2, a < 6, a++, For[b = 2, b < 6, b++, AppendTo[rr, a^b]]]

But any decent Mathematica programmer is aware of how inefficient Append,
AppendTo, Prepend, PrependTo and Insert are

You have many other ways, which are more efficient. Note that Do and For
return Null, and what you do is adopting the concept of side effects to
generate lists - a highly inefficient way in Mathematica

Read the documentation on

Table, Array, Flatten

to enhance your programming in Mathematica


On Sun, Jan 20, 2013 at 8:21 AM, Paolo cachecho <> wrote:

> hello i am new to mathmatica.i have the following problem if anyone could
> help.
> For[a = 2, a < 6, a++,
> For[b = 2, b < 6, b++,
> Appendto[rr = {}, a^b]]]
> rr
> but rr remains empty. how can i solve this
> thank you

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.