# Defining function of a vector and symbolic symmetric matrices- mathematica

• Mathematica
• muppet
In summary, the author is looking for a function that takes a vector as an argument and calculates derivatives with respect to the components. He is struggling to define the function and would like help.f

#### muppet

Hi all,
I'd like to define a vector valued function in mathematica 7 as the exponential of a quadratic form, defined with respect to a purely symbolic matrix. What I want to do with it is to take derivatives with respect to the components of my vector, and evaluate the result when all components of the vector vanish (i.e. the result will just be a sum of products of matrix components). I'm struggling to define a function that takes a vector as an argument- can anyone tell me a good way of doing this?

It would also be helpful to me if I could construct a symmetric symbolic matrix (in a slightly less messy way than adding a symbolic matrix to its transpose), so that it presents an answer in the most simple form, although that's not so essential as I can simplify the result myself if needs be.

Would you consider, to help you get the answer you are looking for, using Mathematica to manually show the steps you would like it to calculate for you for the simplest, but non-trivial, example you can come up with? Perhaps a 3x3 matrix with simple symbolic entries somewhat like you might expect to have?

Thanks for your reply. As it happens I already know the answer I'm looking for; it's a field theory calculation that's in plenty of books and can be worked out using a few diagrams. It's for a homework in which the derivation of the result is the important thing and it's been suggested that we get a computer to take our derviatives for us, as the procedure generates a very large number of terms only to simplify enormously at the end. The problem I have is getting Mathematica to understand what I want it to do!

Well I've now solved my problem, albeit in a very crude way- at the simplest level, it was a question of getting the syntax right (in spite of, rather than aided by, the documentation- f[{x,y,z}_] doesn't work, wheras f[{x_,y_,z_}] does- this despite the command ?f automatically translating f[{x,y,z}_] into f[{x_,y_,z_}]...).

It would still be nice to know, however, if there's a slicker way of defining functions of a vector- preferably one that didn't involve writing the list out explicitly, and that could allow me to readily generalize my approach to an input of arbitrary length with minimal effort.

If you don't need to name the individual components or if you can access the components with your own code then you can just name the vector, like this:

In:= f[v_]:=Norm[v];
f[{3,4}]

Out= 5

That works with arbitrary length vectors and minimal effort.

Actually, when you define f[{x,y,z}_] it did not get turned into f[{x_,y_,z_}], it actually gets turned into f[{x _, y _, z _}]

What happens, is
f[{x,y,z}_]
is actually
f[Times[{x,y,z},_]]
and since Times has the Attribute Listable, it becomes
f[{Times[x, _], Times[y, _],Times[z, _]}]
which in StandardForm is
f[{x _, y _, z _}]

When you did ?f, it showed the UpValue that you had defined, but if you look closely, there are spaces between the Symbols and the Blanks which means Times, as opposed to the shorthand for a named pattern.

And what Bill says is completely correct. Although you could go further by requiring the definition only to fire if, e.g., it is given a List

f[lst_List] := Norm[lst]

or a list of length three

f[lst:{_,_,_}] := Norm[lst]

etc...