Defining function of a vector and symbolic symmetric matrices- mathematica

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.
  • #1
muppet
608
1
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.

Many thanks in advance.
 
Physics news on Phys.org
  • #2
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?
 
  • #3
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!
 
  • #4
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.
 
  • #5
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[3]:= f[v_]:=Norm[v];
f[{3,4}]

Out[4]= 5

That works with arbitrary length vectors and minimal effort.
 
  • #6
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.
 
  • #7
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...
 

1. What is a vector in mathematics?

A vector in mathematics is a mathematical object that has both magnitude and direction. It is represented by an arrow and can be used to represent quantities such as velocity, force, or displacement.

2. How is a vector defined in Mathematica?

In Mathematica, a vector is defined using the "Vector" function, which takes in a list of elements and creates a vector object. For example, Vector[{1,2,3}] creates a vector with elements 1, 2, and 3.

3. What is a symbolic symmetric matrix?

A symbolic symmetric matrix is a mathematical object that represents a square matrix with elements that are symbolic variables. It has the property that the element in the i-th row and j-th column is equal to the element in the j-th row and i-th column.

4. How can a symbolic symmetric matrix be defined in Mathematica?

In Mathematica, a symbolic symmetric matrix can be defined using the "SymmetricMatrix" function, which takes in a list of elements and creates a symbolic matrix with the elements symmetrically arranged. For example, SymmetricMatrix[{{a, b}, {b, c}}] creates a 2x2 symbolic symmetric matrix with elements a, b, and c.

5. Can vector and symbolic symmetric matrices be used together in Mathematica?

Yes, vector and symbolic symmetric matrices can be used together in Mathematica. They can be combined using various mathematical operations such as addition, subtraction, and multiplication to perform calculations and solve equations.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
26K
Replies
14
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Programming and Computer Science
Replies
1
Views
684
Replies
9
Views
1K
  • Introductory Physics Homework Help
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • General Math
Replies
11
Views
1K
  • Linear and Abstract Algebra
Replies
15
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Back
Top