Defining function of a vector and symbolic symmetric matrices- mathematica

Click For Summary

Discussion Overview

The discussion revolves around defining a vector-valued function in Mathematica, specifically focusing on the exponential of a quadratic form with respect to a symbolic matrix. Participants explore methods for taking derivatives of this function and simplifying results, as well as constructing symmetric symbolic matrices.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant seeks guidance on defining a vector-valued function in Mathematica that can handle derivatives and evaluate at zero components.
  • Another participant suggests manually demonstrating the desired calculations with a simple example to clarify the problem.
  • A participant mentions that the task is part of a homework assignment where the derivation process is crucial, and they are looking for a way to automate derivative calculations in Mathematica.
  • A participant shares a solution involving correct syntax for function definitions, noting the difference between using f[{x,y,z}_] and f[{x_,y_,z_}].
  • Another participant provides an example of defining a function that works with arbitrary length vectors without naming individual components.
  • A participant clarifies the behavior of the f[{x,y,z}_] syntax, explaining how it is interpreted in Mathematica and the implications for function definitions.
  • Further suggestions include defining functions that only activate under specific conditions, such as when given a list or a list of a certain length.

Areas of Agreement / Disagreement

Participants express various approaches and solutions to the problem, but there is no consensus on a single best method for defining vector functions or handling symbolic matrices in Mathematica.

Contextual Notes

Participants highlight limitations in the Mathematica documentation and syntax nuances that may lead to confusion when defining functions. There is also an emphasis on the need for clarity in function definitions to avoid unexpected behavior.

muppet
Messages
602
Reaction score
0
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
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[3]:= f[v_]:=Norm[v];
f[{3,4}]

Out[4]= 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...
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
28K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
5
Views
2K