Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to define vector function in Mathematica

  1. May 15, 2012 #1
    How you define vector function in Mathematica?

    For example, f is a vector function and f=(xy,yz,zx). How to define this in Mathematica and then how to calculate the value of the components of f for any number x, y, and z?

    For scalar functions it goes as this:

    f[x_]:=x^2
    f[4]

    Any idea for vectors?
     
  2. jcsd
  3. May 16, 2012 #2
    Can you use this to get you started?

    You could define this to be just what your definition said:

    f[v_List]:={v[[1]]*v[[2]],v[[2]]*v[[3]],v[[3]]*v[[1]]}

    The {} around your result says your f is returning a vector and you calculate each element of that vector.

    Or you can use tricky coding that just happens to do the same thing in this particular case.

    In[1]:= f[v_List]:=RotateLeft[v]*v;

    In[2]:= f[{x,y,z}]
    Out[2]= {x y,y z,x z}

    In[3]:= f[{3,Pi,-2}]
    Out[3]= {3 Pi,-2 Pi,-6}
     
    Last edited: May 16, 2012
  4. May 17, 2012 #3
    Or you could define this as

    f[{x_,y_,z_}]:={x y,y z,z x}

    if that would be easier to understand

    There are at least a dozen different ways of doing almost anything in Mathematica
     
  5. May 17, 2012 #4
    Thank you very much :)

    Buy the way, is there any way to delete your post here before first reply in a case you have already found the answer?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook