# Function output of two lists are only diagonal elements

I'm having a little crysis over here. What I basically want to do is some sort of 3D-Plot, but I'm only interested in the resulting values. I have two vectors x and p:

x={x1,x2}; p={p1,p2};


and I want to calculate the value of the function f depending on 2 variables, for example

f[x_,p_]=x*p;


The input

f[x,p]


however does only calculate the diagonal elements and not all terms f[x1,p1], f[x1,p2], f[x2,p1] and f[x2,p2] what I would intuiveley expect from it.

I tried some "Map" commands but didn't get the desired result. Could someone please help me out? And if possible even share some insight of why Mathematica is doing only the diagonal elements by default? I would be very interested in it because I have the feeling that my way of thinking is often quite perpendicular to the way Mathematica does -.-

• You want something like Outer[Times, x, p] in your function. Just multiplying lists in the fashion of your example will give the respective elements multiplied, e.g., {a,b,c}*{d,e,f} results in {ab,be,cf}.
– ciao
Jan 31, 2014 at 0:44
• Thanks alot, in the more general case of f not simply being a multiplication it will be Outer[f,x,p] as I checked just now. Edit: btw. How can I write in code-style in comments? Jan 31, 2014 at 0:51
• @user104857 for code in comments use backticks: a to print a Jan 31, 2014 at 2:20

Times@@@Tuples[{x, p}]