# local variable naming & symbolic argument

I'm stuck here with my variable assignment in this scenario

AntennaPower[measure_, antenna_] :=
Module[{{x1, x2, sd1} = measure, {xa, ya} = antenna},
N[ sd1*(4*Pi*((xa - x1)^2 + (ya - y1)^2)/1000)]]

AntennaPower[{2000, 0, 1/2}, {5, 60}]
Error message is Module::lvset: Local variable specification {{x1,x2,sd1}={2000,0,1/2},{xa,ya}={5,60}} contains {x1,x2,sd1}={2000,0,1/2}, which is an assignment to {x1,x2,sd1}; only assignments to symbols are allowed. >>

-
You can not assign to a list in local variable specification as You did {x1,x2,sd1}=measure. Use an explicit names in function declaration, eg. AntennaPower[{x1_,x2_,sd1_},{xa_,ya_}] for local variables. – mmal Oct 28 '12 at 12:23
Are you and this user mathematica.stackexchange.com/questions/13745/… the same person? – Dr. belisarius Oct 28 '12 at 12:31
You asked the same question earlier and you were given a simple answer and asked to read some basic tutorials... did you do that? This would've been answered had you simply looked up Module in the documentation. – R. M. Oct 28 '12 at 14:29
Same question, different user. mathematica.stackexchange.com/q/13576/973 – Fred Kline Oct 28 '12 at 19:21

AntennaPower[measure_List, antenna_List] :=
Module[{x1,x2,xa,ya,sd2},
{x1, x2, sd1} = measure;
{xa, ya} = antenna;
N[ sd1*(4*Pi*((xa - x1)^2 + (ya - y1)^2)/1000)]
]


The point here is that the first argument to Module can only be a sequence of symbols (or of assignments x=x0,y=y0,...) but no expressions are allowed. Just an aside: I changed your argument pattern to _List so that the functions only match when the arguments have the head List.

Edit

Of course there are many different ways to do what you want. mmal pointed out in his comment that you can also use

AntennaPower[{x1_,x2_,sd2_}, {xa_,ya}] :=
Module[{},
N[sd1*(4*Pi*((xa - x1)^2 + (ya - y1)^2)/1000)]]


In your case (where you know the length of your input lists) it is probably the wiser choice as this version only evaluates for the correct form of the input arguments.

-

You can not assign to a list in local variable specification as You did {x1,x2,sd1}=measure. You can assign specific parts of dummy variables:

AntennaPower[measure_, antenna_] :=
Module[{x1=measure[[1]], x2=measure[[2]], sd1=measure[[3]], xa=antenna[[1]], ya=antenna[[2]]},
N[sd1*(4*Pi*((xa - x1)^2 + (ya - y1)^2)/1000)]
]


or use equivalent sebhofer's method. But this might be dangerous when the length of actual arguments is different. Use an explicit names in function declaration, eg.

AntennaPower[{x1_,x2_,sd1_},{xa_,ya_}] :=
N[sd1*(4*Pi*((xa - x1)^2 + (ya - y1)^2)/1000)]


EDIT: To end this lengthy discussion You can use method proposed by sebhofer with argument checking by:

AntennaPower[measure_, antenna_] := Module[{x1, x2, sd1, xa, ya},
{x1, x2, sd1} = measure;
{xa, ya} = antenna;
N[sd1*(4*Pi*((xa - x1)^2 + (ya - y1)^2)/1000)]
] /; (Length[measure] == 3 && Length[antenna] == 2);

-
hehe... what are we going to do now?? :) – sebhofer Oct 28 '12 at 12:36
+1 for You of course! – mmal Oct 28 '12 at 12:40
Well it's my pleasure to return the favour! – sebhofer Oct 28 '12 at 12:41