Re: Re: Telling Mathematica that a symbol is going to be a List?
- To: mathgroup at smc.vnet.net
- Subject: [mg50920] Re: [mg50842] Re: Telling Mathematica that a symbol is going to be a List?
- From: Ichigaku Takigawa <1gac at main.ist.hokudai.ac.jp>
- Date: Tue, 28 Sep 2004 00:58:29 -0400 (EDT)
- Organization: Hokkaido University
- References: <ciqvop$in9$1@smc.vnet.net> <200409230927.FAA08084@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, Your problem seems to be in the "Part" function like "array[[i]]". In mathematica, like a[[3]], there are immediately (and internally) evaluated expressions when it is called. The following note might help you, especially "An Introduction to demystify scary things" part: "Working with Unevaluated Expressions" by R. Villegas http://library.wolfram.com/conferences/devconf99/villegas/UnevaluatedExpressions/ It's my understanding that error messages in mathematica sometimes will mean just a warning, so if your logic is correct, the result will often work well though mathematica will display an message (in this case, indeed you can just use "Off" function to suppress the corresponding message.) In your case, when evaluating "m", mathematica will think that the length of "d" is undefined and just wonder if "d" object has the i-th element required for an access to array elements. For example, simply by typing Remove[m, d] m := {{d[[1]], 0, 0}, {0, d[[2]], 0}, {0, 0, d[[3]]}} m you will get the same error message (this is a evaluating stage before applying "/." rules when "m" called). Moreover, you can also use the following expressions to do what you want instead of what was previously mentioned in this list (although I recommend that you define it as a function like "m[d_List] := DiagonalMatrix[d]" and then use it as "m[{1,2,3}]".) m1 := {{d[[1]], 0, 0}, {0, d[[2]], 0}, {0, 0, d[[3]]}} Block[{d = {1,2,3}}, m1] for local binding of variables, or something like m2 := {{d[1], 0, 0}, {0, d[2], 0}, {0, 0, d[3]}} m2 /. d -> {1, 2, 3} /. l_[i_] :> l[[i]] (I know the second one seems to be a little bit tricky, but this might show a example of "Part" evaluating problem) At Thu, 23 Sep 2004 05:27:26 -0400 (EDT), AES/newspost wrote: > But the alternative fragment > > m := {d[[1], 2 d[[2], 3d[[3]]} > > s = m /. {d->{1,2,3}} > > which my mental model, augmented by a model of how "->" works, says > should be OK also. Instead this fragment puts up error messages -- and > then, ignoring its own trouble messages, goes ahead and works OK anyway!! -- Ichigaku Takigawa Laboratory for Pattern Recognition and Machine Learning Research Group of Mathematical Information Science Division of Computer Science Graduate School of Information Science and Technology Hokkaido University Kita 14, Nishi 9, Kita-ku, Sapporo 060-0814, Japan tel: +81-11-706-6854 email: 1gac at main.ist.hokudai.ac.jp www: http://ips9.main.ist.hokudai.ac.jp/~1gac/
- References:
- Re: Telling Mathematica that a symbol is going to be a List?
- From: AES/newspost <siegman@stanford.edu>
- Re: Telling Mathematica that a symbol is going to be a List?