0
$\begingroup$

I have a function which depends on more than 30 parameters and I want to symbolically compute the derivatives with respect to the individual parameters.

From the documentation of the D operator I got the impression that I have to explicitly mention all parameters in the function definition. Is there a way around it? That is, is it possible to take the derivative of a function which is an expression of another symbol, which doesn't appear in the function signature?

If not, is there a way to write the function parameter list on multiple lines, for example like this:

Foo[(* These parameters describe... *)
     x11, y12, z13,
    (* And these parameters describe.... *)
     x21, y22, y23,
    (* Many more parameters... *)] := (* Function implementation... *)
$\endgroup$
1
  • $\begingroup$ Have you looked at the Dt[] function? $\endgroup$
    – Somos
    Commented Oct 31, 2019 at 19:19

1 Answer 1

1
$\begingroup$
Clear["Global`*"]

Define the variables using an indexed variable

n = 3; (* change as desired *)

var = Array[x, n];

Define the function

Evaluate[f @@ var] = Sqrt[Total@var^2]

(* Sqrt[(x[1] + x[2] + x[3])^2] *)

Taking the partial derivatives

enter image description here

D[f @@ var, Sequence @@ var]

(* (3 (x[1] + x[2] + x[3])^3)/((x[1] + x[2] + x[3])^2)^(5/2) - (
 3 (x[1] + x[2] + x[3]))/((x[1] + x[2] + x[3])^2)^(3/2) *)

or for a vector derivative

enter image description here

D[f @@ var, {var}]

(* {(x[1] + x[2] + x[3])/Sqrt[(x[1] + x[2] + x[3])^2], (
 x[1] + x[2] + x[3])/Sqrt[(x[1] + x[2] + x[3])^2], (
 x[1] + x[2] + x[3])/Sqrt[(x[1] + x[2] + x[3])^2]} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.