Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #13234
| From | <bar@robox.ii.up.krakow.pl> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: problem with append |
| Date | 2013-01-21 05:07 +0000 |
| Message-ID | <kdiidl$ncm$1@smc.vnet.net> (permalink) |
| References | <kdg2kv$hf8$1@smc.vnet.net> |
| Organization | Time-Warner Telecom |
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
>
Try this:
r = {};
For[a = 2, a < 6, a++,
For[b = 2, b < 6, b++,
AppendTo[rr, a^b]]]
rr
or
Table[
Table[a^b, {b, 2, 5}], {a, 2, 5}]
Table[a^b, {a, 2, 5}, {b, 2, 5}]
but it is not the same, I'm not sure what You mean
remember : Table is faster then For , AppendTo is extremally slow
see
http://blog.wolfram.com/2011/12/07/10-tips-for-writing-fast-mathematica-code/
Try examples:
n = 200;
rr = {};
Timing@For[a = 2, a < n, a++,
For[b = 2, b < n, b++,
AppendTo[rr, a + b]]]
{18.4572, Null}
and
Timing[rr = Table[a + b, {a, 2, n - 1}, {b, 2, n - 1}];]
{0.104007, Null}
(I changed a^b -> a+b )
Olaf,
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
problem with append Paolo cachecho <paolocach@gmail.com> - 2013-01-20 06:25 +0000 Re: problem with append svkeeley@aol.com - 2013-01-21 05:06 +0000 Re: problem with append <bar@robox.ii.up.krakow.pl> - 2013-01-21 05:07 +0000
csiph-web