Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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


The input


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 -.-

share|improve this question
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 '14 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? –  user104857 Jan 31 '14 at 0:51
@user104857 for code in comments use backticks: `a` to print a –  Mr.Wizard Jan 31 '14 at 2:20

1 Answer 1

Here's a way similar to the one proposed by rasher in the comments:

Times@@@Tuples[{x, p}]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.