# Inputting two arrays for a module in Mathematica

I am relatively new to the Mathematica enviroment and not sure where I am going wrong. I have evaluated the question and understand it, but dont know how to exactly create a module for it.

The problem is:

• I need to calculate PowerDensity at a location $(x,y)$
• I am given the power $P$ at the source and its location $(x2,y2)$
• To calculate the PowerDensity, you use $P_d= \frac{P}{4\pi r^2}$
• The two $x$ and $y$ coordinates compute to give : $P_d = \frac{P}{(4*\pi*(y_2 - y_1)^2 - (x_2 - x_1)^2)}$

How do I write a Module like:

PowerDensity[antenna_, loc_] := Module[(* Enter your code here*)]


so the user would enter e.g. PowerDensity[{1000,1000,12}, {0,0}]?

So far I have this:

PowerDensity[antenna_, loc_] := Module[{xone, yone, w} {xtwo, ytwo},
PD = w/(4*Pi*(ywo - yone)^2 - (xtwo - xone)^2),
print[PD]
]


But it is not working. Any help?

• Where's the power in PowerDensity[{1000,1000,12}, {0,0}]? You might be interested in the function SquaredEuclideanDistance[]... – J. M. will be back soon Oct 24 '12 at 16:34
• {1000,1000,12} is {xone,xtwo, and the power} – Daniel R Oct 24 '12 at 16:37
• {0,0} is the location where we want to find the powerdensity..so the x and y of that point – Daniel R Oct 24 '12 at 16:38

A few things I see right away:

• Whatever function you create inside the Module needs to depend on the variables antenna and loc. Figure out whether antenna and loc will be lists of numbers or just numbers. If they are lists, like a pair of $x$ and $y$ numbers, then your function will have to depend on antenna[[1]], antenna[[2]], etc.

• Also, you have the structure for Module wrong. To figure out how a built-in function works, try typing

?Module


and the Mathematica help function will show you how to use Module. Try building the simplest Module that you can, just so you know how the function works, then once you have a working example you can modify it to deal with the physics problem above.

ETA: I think your last formula is wrong (try and figure out what $r$ is in terms of the two given coordinates). You have two commas in the Module environment, where the second one should be a semicolon. And finally, the Print function must have its first letter capitalized just like any built-in mathematica function.

I don't know what the policy is around here about answering homework questions. I was trying to walk you to the answer without actually giving it, but I don't know that you'll get there from where you are. I would write the function the following way:

PowerDensity[antenna_, loc_] := Module[{r, power},
r = Sqrt[(antenna[[1]] - loc[[1]])^2 + (antenna[[2]] - loc[[2]])^2];
power = antenna[[3]];
power/(4 Pi r^2)]

• Antenna will be plain {x,y, power}, loc will be {x,y}.. that is a list yeah? – Daniel R Oct 24 '12 at 16:46
• Both of those are lists. Inside Module, you'll call power as antenna[[3]]. xone would be antenna[[1]], and so on. – user4368 Oct 24 '12 at 16:48
• no actually they are just numbers – Daniel R Oct 24 '12 at 16:50
• ohh okay, i see – Daniel R Oct 24 '12 at 16:50
• i'll try that right now, thanks! :) – Daniel R Oct 24 '12 at 16:51