Re: Simple List question. HELP.

*To*: mathgroup at smc.vnet.net*Subject*: [mg39418] Re: [mg39389] Simple List question. HELP.*From*: Tomas Garza <tgarza01 at prodigy.net.mx>*Date*: Fri, 14 Feb 2003 03:23:44 -0500 (EST)*References*: <200302130955.EAA20703@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

I think you needn't create an empty 2 dimensional list in the first place. Why not start directly with your first element, i.e., the pair {0, 1}? In[1]:= lst = {{0, 1}} Out[1]= {{0, 1}} The errors and beeps you get are a warning that you are using the wrong syntax. To denote any element of a list you must use a double bracket: In[2]:= lst[[1]] Out[2]= {0, 1} bracket as you are doing. {{2, c}} is not a pair, but a list with a single element which is the pair {2, c}. Simply append the pair {2, c}: In[3]:= lst = Append[lst, {2, c}] Out[3]= {{0, 1}, {2, c}} and now you obtain a 2 dimensional list with two elements, as desired. Now, I suggest you don't use Append, which is all right if you're dealing with small lists, but becomes extremely slow when the length of the lists involved increase. I'd rather use, e.g., In[4]:= lst = {lst, {3, d}} Out[4]= {{{0, 1}, {2, c}}, {3, d}} and so on. There is no mystery at all. You made a mistake in using lst[1] (with a single bracket) instead of lst[[1]], and then you made another mistake when appending a list {{1, 2}} instead of a pair {1, 2}. Tomas Garza Mexico City ----- Original Message ----- From: "Daniel Heneghan" <dhenegha at bway.net> To: mathgroup at smc.vnet.net Subject: [mg39418] [mg39389] Simple List question. HELP. > > I am new to Mathematica. This is vexing. All I want to do is create a > 2-dimensional list so that I can enter x,y values and then plot the > list. I want to do this programmatically. I am having such incredible > trouble trying to accomplish this simple task. I know that there is > probably a Mathematica optimized way to do this, but I and trying to > write a little program and for now I want to stay with paradigms that I > am familiar with. Here is what I have been doing. > > Create a 2 dimensional list. > In[532] lst={{}} > Out[532]= {{}} > > Enter the first pair into the first place in the list. > In[533]:= lst[1]={{0,1}} > > Errors and beeps here, but it does seem to record the correct values. > Set::write: Tag List in {{}}[1] is Protected. > Out[533]={{0,1}} > > Add anoter pair of values. > > In[534]:= lst=Append[lst,{{1,2}}] > Out[534]= {{},{{1,2}}} > The second pair is OK, but the first pair has been obliterated. > > Add another pair. Now all subsequent entries are OK, but I still have > lost the first pair. > In[535]:= lst=Append[lst,{{2,c}}] > Out[535]= {{},{{1,2}},{{2,c}}}-- > > > What is going on? What are the mysteries of working with lists in > Mathematica. In any programming language this is simple. I can't grasp > it in Mathematica. The reason I need to do this is that for the list > plot I need the x values to start at 0 not 1. > > Thanks, > > Daniel Heneghan > Ceara Systems > (212) 696-9208 > ceara at bway.net > > >

**References**:**Simple List question. HELP.***From:*"Daniel Heneghan" <dhenegha@bway.net>

**Re: Detecting unsuccessful computations**

**Re: Simple List question. HELP.**

**Simple List question. HELP.**

**Re: Simple List question. HELP.**