How to define vector function in Mathematica

Click For Summary

Discussion Overview

The discussion focuses on defining vector functions in Mathematica, specifically how to implement a vector function like f = (xy, yz, zx) and compute its components for given values of x, y, and z. The scope includes programming techniques and function definitions within Mathematica.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant asks how to define a vector function in Mathematica and calculate its components for specific values.
  • Another participant suggests defining the function using a list input, providing an example of how to return a vector using the syntax f[v_List]:={v[[1]]*v[[2]],v[[2]]*v[[3]],v[[3]]*v[[1]]}.
  • A different approach is proposed, utilizing RotateLeft to achieve the same result with the definition f[v_List]:=RotateLeft[v]*v.
  • Another participant offers an alternative definition using pattern matching with f[{x_,y_,z_}]:={x y,y z,z x}, suggesting it may be easier to understand.
  • Participants note the existence of multiple ways to accomplish similar tasks in Mathematica.
  • One participant inquires about the possibility of deleting their post before receiving a reply if they find the answer elsewhere.

Areas of Agreement / Disagreement

There is no explicit consensus on a single method for defining vector functions, as multiple approaches are presented, and participants share different coding techniques.

Contextual Notes

Some methods depend on specific input formats, and the discussion does not resolve which method is superior or more appropriate for all cases.

Who May Find This Useful

Users interested in programming in Mathematica, particularly those looking to define and manipulate vector functions.

nikolafmf
Messages
112
Reaction score
0
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?
 
Physics news on Phys.org
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:
Bill Simpson said:
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]]}

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

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
Replies
5
Views
4K