Update
Actually, I decided the OverVector
solution by @Brett Champion is not a good idea after all. The reason is that it deceives you into thinking you can safely distinguish between the vector variable $\vec{v}$ and the variable v
. This is not the case: set v = 7
after defining OverVector[v]
with its three components, and you lose the vector definition because now OverVector[v]
will return OverVector[7]
.
So my conclusion is that I would definitely stick with the following approach which has worked well for me in the past (the rest is a slightly edited version of my original post):
If you're doing tensor analysis and need symbolic manipulations where the vector components are functions such as $v = \{v_1(x,y,z), v_2(x,y,z), v_3(x,y,z)\}$, you could also make use of the following:
v = Through[Array[Subscript["v", #] &, 3][x, y, z]]
The output is $\{v_1[x,y,z],v_2[x,y,z],v_3[x,y,z]\}$. These can be used in symbolic manipulations: You can now do operations on the components of v
, such as D[v[[1]], x]
, or on the vector v
as a whole, such as D[v,x]
. In tensor analysis, these symbolically defined components are what you need most. But you can also assign specific functions or constants to these components:
If I were to assign, say, Subscript["v", 1][x, y, z] = x^2
, this would define SubValues
for the Subscript
operator. The latter is similar to OverVector
in that it has no pre-defined meaning in Mathematica, see "Operators without Built-in Meanings" in the documentation. The recursion problem is avoided by making the component names into strings, whereas the vector name is a symbol.
To see what other subscripted variables are defined, type SubValues[Subscript]
to get variables indexed by [x,y,z]
as above, or DownValues[Subscript]
to find subscripted variables such as Subscript["v",0]
that aren't functions of x,y,z
.
Comparing the above suggestion to the definition
OverVector[w] = {Subscript[w,1][x,y,z],Subscript[w,2][x,y,z],Subscript[w,3][x,y,z]}
my recipe allows you to retain simple notation for your vectors (assuming that you'll mostly be typing their names, not the names of the components).
Edit
In response to the comment by @murray let me add that if you don't like the output with its verbose component form for your vector v
, it is always possible to add rules that format the results in a wide variety of ways. For example, assuming my above template for defining vectors, you could define the following rule:
nice = {Through[Array[Subscript[name_String, #] &, 3][x, y, z]] :> name}
Then compare the output of v
and v/.nice
. The latter just replaces the list of components by the string name
which all components have in common (which is also the name of the vector symbol v
). For more on how to work with these objects, you may want to look at this MathGroup post.
Part
, $sin$, or any function $f$), then writing $v = v_i$ equals writing $v = f(v)$ which is recursive definition (if $=$ stands for assignment and not for testing). Just like @Helen said it. $\endgroup$