Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13254

Re: problem with append

From David Bailey <dave@removedbailey.co.uk>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: problem with append
Date 2013-01-23 04:18 +0000
Message-ID <kdnoaq$727$1@smc.vnet.net> (permalink)
References <20130120062148.0CB436854@smc.vnet.net> <kdiibf$n7m$1@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


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


Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: problem with append Bob Hanlon <hanlonr357@gmail.com> - 2013-01-21 05:05 +0000
  Re: problem with append David Bailey <dave@removedbailey.co.uk> - 2013-01-23 04:18 +0000

csiph-web