Re: Nested Lists, Definition and Evaluation.
- To: mathgroup at smc.vnet.net
- Subject: [mg59758] Re: [mg59729] Nested Lists, Definition and Evaluation.
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sat, 20 Aug 2005 03:13:47 -0400 (EDT)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
You need to convert the strings to symbols if you want a11=IdentityMatrix[2] to affect b b = ToExpression[ Table[Symbol["a" <> ToString[i] <> ToString[j]], {i, 2}, {j, 2}]]; a11 = IdentityMatrix[2]; b[[1,1]] {{1, 0}, {0, 1}} b[[1,1]][[1,1]] is the same as b[[1,1,1,1]] when referring to the value of the element but the first form cannot be used on the LHS of a Set. The LHS would be partially evaluated and no longer make sense. Bob Hanlon > > From: "Alexander" <beginning.physst at mail.ru> To: mathgroup at smc.vnet.net > Date: 2005/08/19 Fri AM 04:31:51 EDT > Subject: [mg59758] [mg59729] Nested Lists, Definition and Evaluation. > > Hello! > > Here is simple example of defining list: > > b = Table[Symbol["a" <> ToString[i] <> ToString[j]], {i, 2}, {j, 2}]; > a11 = IdentityMatrix[2]; > b[[1,1]][[1,1]] > > Output will be number 1. > > Then we type another command: > b[[1,1]][[1,1]]=2 > > wich cause error message. > > If we type ?b the structure of b can be seen: > Global`b > b = {{a11, a12}, {a21, a22}} > > And I wonder, how to change elements of aij from b? It's interesing > question about how mathematica think things and how evaluate them. > > So, the questions are: > 1) Why code above produce error message? > 2) What difference between b[[1,1]][[1,1]] and > b[[1,1,1,1]] notation? > > Here is an example concerning the second question: > This code doesn't produce an error: > > a11 = IdentityMatrix[2]; > b = Table[Symbol["a" <> ToString[ > i] <> ToString[j]], {i, 2}, {j, 2}]; > b[[1, 1, 1, 1]] = 3 > > but this does: > > a11 = IdentityMatrix[2]; > b = Table[Symbol["a" <> ToString[ > i] <> ToString[j]], {i, 2}, {j, 2}]; > b[[1, 1]][[1, 1]] = 3 > > Why? > > Sorry for my obscure speech, and thanks for your answers! > >