Re: using predefined expressions in functions [newbie question]

*To*: mathgroup at smc.vnet.net*Subject*: [mg100212] Re: [mg100167] using predefined expressions in functions [newbie question]*From*: "David Park" <djmpark at comcast.net>*Date*: Thu, 28 May 2009 04:29:01 -0400 (EDT)*References*: <14105722.1243411978425.JavaMail.root@n11>

I don't see how the VectorAnalysis package is yet used in your example. Using SetDelayed means that the right hand side of the definition is not evaluated and the definition never sees any of the left hand side arguments on the right hand side. The arguments are useless and never get substituted. Use Set instead. R1 := {x1, y1, z1} R2 := {x2, y2, z2} f[x1_, y1_, z1_, x2_, y2_, z2_] = R1.R2 f[1, 2, 3, 4, 5, 6] 32 Perhaps it is just an example, but I don't see how this function does much. Isn't it almost as easy to write {1, 2, 3}.{4, 5, 6}? I often see questions on MathGroup where definitions are written in a non-localized manner, where parts of the definition are written in separate statements outside the principal definition. Although this will sometimes work, it seems to be an invitation to trouble. It is better to keep the definition together in one localized structure. I would tend to write your definition as: f[x1_, y1_, z1_, x2_, y2_, z2_] := {x1, y1, z1}.{x2, y2, z2} or as: f[x1_, y1_, z1_, x2_, y2_, z2_] := With[{R1 = {x1, y1, z1}, R2 = {x2, y2, z2}}, R1.R2] David Park djmpark at comcast.net http://home.comcast.net/~djmpark/ From: ChangMo [mailto:nichthierwohne at gmail.com] Hi, I've been trying to write a function using some predefined expressions, but the function assignment seems to understand the symbols in the expressions as literals. eg., Needs["VectorAnalysis`"] R1 := {x1,y1,z1} R2 := {x2,y2,z2} f[x1_,y1_,z1_,x2_,y2_,z2_] := R1 . R2 f[1,2,3,4,5,6] gives the output x1 x2 + y1 y2 + z1 z2 instead of 32 ( = 1*4 + 2*5 + 3*6 ) Can anyone help me with this? Thanks for your attention. -ChangMo