Re: Structure modification and related questions

*To*: mathgroup at smc.vnet.net*Subject*: [mg13890] Re: [mg13857] Structure modification and related questions*From*: Jon Prudhomme <prudhomj at elwha.evergreen.edu>*Date*: Sun, 6 Sep 1998 02:55:27 -0400*Sender*: owner-wri-mathgroup at wolfram.com

Hello, A.1) You should be able to alter parts of a list x by using x[[3]]=0; I have never had any trouble with that. In[1]:= x=Table[i,{i,4}] Out[1]= {1,2,3,4} In[2]:= x[[3]]=0 Out[2]= 0 In[3]:= x Out[3]= {1,2,0,4} A.2) The function ReplacePart[list, newelement,position] will replace the element list[[position]] with newelement. In[4]:= ReplacePart[x,5,3] Out[4]= {1,2,5,4} A.3) Structures with variables in them like x={1,y,4} will change when y changes. In[5]:= x[[3]]=y Out[5]= y In[6]:= y={2,3};x Out[6]= {1,2,{2,3},4} In[7]:= y={2,5};x Out[7]= {1,2,{2,5},4} Hope that helps. Jon Prudhomme prudhomj at elwha.evergreen.edu On Wed, 2 Sep 1998, Roberto Moriyon wrote: > Hello, > > I am working with a big structure (actually, it is a list), like > > x=Table[i, {i,10000}] > > Q.1) Can I modify x[[3]], let's say, without having to create another > list of 10000 elements? (the obvious thing for me to try, x[[3]]=0, > does not work). > > Q.2) In the same spirit, are there any functions similar to Insert and > Delete, that modify directely the expression affected by them, without > taking a whole copy? > > Q.3) Related to Q.1&2, is it possible in Mathematica that two structures > (or lists, for that sake) have some parts in common? What I mean by > this is that, for example, I would like to have the variable x equal to > the second element of {1,{2,3},4}, so that in case the 3 is changed by > a 5 in one of them, it is also changed in the other one. > > Thank you for any help you can give me on this > > Roberto Moriyon > > -- > > Roberto Moriyon > Departamento de Ingenieria Informatica Universidad Autonoma de Madrid > 28049 Madrid > > Phone: +34-91-397-4350 > Fax: +34-91-397-5277 > > >