[Date Index]
[Thread Index]
[Author Index]
Re: Use of delayed assignment, :=, with a list
*To*: mathgroup at smc.vnet.net
*Subject*: [mg91788] Re: Use of delayed assignment, :=, with a list
*From*: "David Park" <djmpark at comcast.net>
*Date*: Sun, 7 Sep 2008 22:55:03 -0400 (EDT)
*References*: <ga077v$oto$1@smc.vnet.net>
You don't give us the precise code that causes the problem. But, in any
case, instead of doing direct assignment of the elements, why not define an
opticalMatrix with parameters. I suspect those are the things you would
actually be working with.
opticalMatrix[f_, zomeasure_] := {{1, zomeasure}, {-(1/f), 1 -
zomeasure/f}}
Then you can directly multiply two matrices as follows:
opticalMatrix[f1, z1].opticalMatrix[f2, z2] // Simplify
{{1 - z1/f2, z1 + z2 - (z1 z2)/f2}, {-((f1 + f2 - z1)/(f1 f2)),
(f1 (f2 - z2) + z1 z2 - f2 (z1 + z2))/(f1 f2)}}
It is always better to localize parameters or variables to a definition by
using arguments than having them floating around free in your notebook.
--
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/
"phillman5" <PHILLMAN5 at gmail.com> wrote in message
news:ga077v$oto$1 at smc.vnet.net...
>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 := . . .
>
>
Prev by Date:
**Re: force variable to be real**
Next by Date:
**Re: LU Decomposition w/o Pivoting**
Previous by thread:
**Re: Use of delayed assignment, :=, with a list**
Next by thread:
**Re: Use of delayed assignment, :=, with a list**
| |