RE: Structure modification and related questions
- To: mathgroup at smc.vnet.net
- Subject: [mg13893] RE: [mg13857] Structure modification and related questions
- From: Daniel CLEMENT <dclement at mail.cpod.fr>
- Date: Sun, 6 Sep 1998 02:55:30 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Hello,
> ----- Original Message -----
> From: Roberto Moriyon [SMTP:Roberto.Moriyon at ii.uam.es]
To: mathgroup at smc.vnet.net
> Sent: Wednesday, September 02, 1998, 7:30:54
> To: mathgroup at smc.vnet.net
> Subject: [mg13857] Structure modification and related questions
>
[...]
>
> 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).
>
According to me this is the role of the ReplacePart function:
x=ReplacePart[x,0,3]
[...]
>
> 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.
>
It is enough to use SetDelayed (:=):
list1={1,{2,3},4}
x:=list1[[2]]
list1=ReplacePart[list1,5,{2,2}] (the 3 is at place {2,2} in list1)
x is now {2,5}
>
> ----- End Of Original Message -----
regards,
Daniel CLEMENT