1

Suppose I have a function that depends on variables $x_1, ... , x_n$. For concreteness I may have $f(x) = v \cdot x$, with $v$ a certain vector.

Now I want to do certain operation with this function, for example to compute its gradient.

I would like to write a mathematica code that works for any n. Thus, I cannot write something like

f[x1_,...,xn_]:= (any clever way to write v . x);

because that would not work for another n: I have to manually write the new simbols x1,...,xn'.

Also, the following would not work:

f[x_]:= v . x;

because then I would not be able to use Derivative, as f is now a function of a single argument (a list), and it is impossible to get the derivative with respect to x[[2]] say. (Right?)

What is the best design to work with this kind of problems?

0 Answers0