Re: Use of delayed assignment, :=, with a list
- To: mathgroup at smc.vnet.net
- Subject: [mg91785] Re: Use of delayed assignment, :=, with a list
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sun, 7 Sep 2008 22:54:30 -0400 (EDT)
- References: <ga077v$oto$1@smc.vnet.net>
phillman5 wrote: > I use simple 2x2 matrixes for each item in a optical train to get the > over all 2x2 matrix. The four elements are a, b, c, d, and I can > assign them easily in one step. > > {{a, b},{c, d}} = any 2x2 matrix > > however some times the rhs has variables, so I'd like to use an > delayed assignment > > {{a, b},{c, d}} := any 2x2 matrix > > this does not work, Mathematica says the two lists are not the same > shape. In particular: > > {{a, b},{c, d}} := {{1, zomeasure}, {-(1/f), 1 - zomeasure/f}} > > where f and zomeasure are variables (maybe not even defined yet). > Mathematica says the lists are not the same shape, but if I use an > assignment operator there is no problem. I am not completely > convinced it is a mere Mathematica notation misunderstanding on my > part because a simpler 2x2 assignment: > > {{q, g}, {h, k}} := {{f, w}, {r, t}} > > works. (Mathematica does respond {{Null, Null}, {Null, Null}}, but g > does have a delayed assignment of w. > > Is there an easier way to do a delayed assignment than each member, a, > b, c, d individually > > tempmatrix := {{1, zomeasure}, {-(1/f), 1 - zomeasure/f}} > a := tempmatrix[[1]][[1]] > b := . . . FWIW, The delayed assignment you provided works as expected on my system. Something else must be going on on your system. In[1]:= {{a, b}, {c, d}} = {{1, 2}, {3, 4}} Out[1]= {{1, 2}, {3, 4}} In[2]:= {{a, b}, {c, d}} Out[2]= {{1, 2}, {3, 4}} In[3]:= {{a, b}, {c, d}} := {{1, zomeasure}, {-(1/f), 1 - zomeasure/f}} Out[3]= {{Null, Null}, {Null, Null}} In[4]:= {{a, b}, {c, d}} Out[4]= 1 zomeasure {{1, zomeasure}, {-(-), 1 - ---------}} f f In[5]:= $Version Out[5]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) Regards, -- Jean-Marc