Search All of the Math Forum:

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

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

 Messages: [ Previous | Next ]
 David Bailey Posts: 714 Registered: 11/7/08
Re: problem with append
Posted: Jan 22, 2013 11:18 PM

On 21/01/2013 05:05, Bob Hanlon wrote:
> rr = {};
> For[a = 2, a< 6, a++,
> For[b = 2, b< 6, b++,
> AppendTo[rr, a^b]]]
>
> rr
>
> Or
>
> rr = Table[a^b, {a, 2, 5},
> {b, 2, 5}]//Flatten
>
> Or
>
> rr = Table[a^Range[2, 5],
> {a, 2, 5}]//Flatten
>
>
> Bob Hanlon
>
>
> On Jan 20, 2013, at 1:21 AM, Paolo cachecho<paolocach@gmail.com> 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
>>

>
I would like to add that I never use AppendTo, but simply Append:

rr=Append[rr,a^b];

This slightly longer form amounts to the same thing internally, and is
much clearer to read, since few Mathematica functions work by changing
their arguments (except those that are normally written as operators, = , := , etc.)

David Bailey
http://www.dbaileyconsultancy.co.uk

Date Subject Author
1/21/13 Chris Arthur
1/21/13 Bob Hanlon
1/22/13 David Bailey
1/21/13 Murray Eisenberg
1/21/13 KING NIGEL-NKI001
1/21/13 yehuda ben-shimol
1/21/13 Tomas Garza Hernandez