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


Groups > comp.soft-sys.math.mathematica > #11958 > unrolled thread

List manipulation?

Started byAndreas Talmon l'Armée
First post2012-10-05 06:44 +0000
Last post2012-10-06 06:08 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  List manipulation? Andreas Talmon l'Armée - 2012-10-05 06:44 +0000
    Re: List manipulation? awnl <awnl@gmx-topmail.de> - 2012-10-06 06:08 +0000

#11958 — List manipulation?

FromAndreas Talmon l'Armée
Date2012-10-05 06:44 +0000
SubjectList manipulation?
Message-ID<k4lvjt$d41$1@smc.vnet.net>
Hi all,

I got a problem with List manipulation. I have the following list item:

  a = -Subscript[50, 5]

and I would like to change the value of 50 to 360-50 and also change the 
sign to +. First I tried to change the sign and then the value and I got 
an outcome I didn't understand. Doing the other way round I get the 
outcome I expected. Does anybody know what the difference is?

Here is the Example file:
http://dl.dropbox.com/u/4920002/Example.nb



a = -Subscript[50, 5]
a[[2, 1]] = 360 - a[[2, 1]]
a[[1]] = -1*a[[1]]
a


b = -Subscript[50, 5]
b[[1]] = -1*b[[1]]
b[[1]] = 360 - b[[1]]
b


-- 
Andreas Talmon l'Armée
TU-Darmstadt
Fachgebiet Strukturmechanik
Hochschulstraße 1
06151-16 6467

[toc] | [next] | [standalone]


#11974

Fromawnl <awnl@gmx-topmail.de>
Date2012-10-06 06:08 +0000
Message-ID<k4oht7$i80$1@smc.vnet.net>
In reply to#11958
Hi,

 >
 > I got a problem with List manipulation. I have the following list item:
 >
 >    a = -Subscript[50, 5]
 >
 > and I would like to change the value of 50 to 360-50 and also change the
 > sign to +. First I tried to change the sign and then the value and I got
 > an outcome I didn't understand. Doing the other way round I get the
 > outcome I expected. Does anybody know what the difference is?
 >
 > Here is the Example file:
 > http://dl.dropbox.com/u/4920002/Example.nb
 >
 >
 >
 > a = -Subscript[50, 5]
 > a[[2, 1]] = 360 - a[[2, 1]]
 > a[[1]] = -1*a[[1]]
 > a
 >
 >
 > b = -Subscript[50, 5]
 > b[[1]] = -1*b[[1]]
 > b[[1]] = 360 - b[[1]]
 > b

what happens is that you change the OwnValue of b in place from

Times[-1,Subscript[50,5]]

to:

Times[1,Subscript[50,5]]

and finally to:

Times[310,Subscript[50,5]]

which you can check from looking at:

OwnValues[b] // FullForm

after every step. The subtlety is that in the second step the b[[1]] on 
the right hand side is evaluated. As usual the b itself is evaluated 
first, which will get rid of Times, and only after that Part ([[]]) 
actually is applied, which you can see from e.g.:

b = -Subscript[50, 5]
b[[1]] = -1*b[[1]]
Trace[b[[1]]]

hth,

albert

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web