Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2014

[Date Index] [Thread Index] [Author Index]

Search the Archive

Better way to test the number of arguments?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg132642] Better way to test the number of arguments?
  • From: pgeipi10 at gmail.com
  • Date: Sun, 27 Apr 2014 02:42:25 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net

Hi,

I have the following code that produces the gradient of a function (with respect to all but the first variable). There is probably a better way that avoids the Switch.

Thank you,

Pavel

ddSaPartial[func_][t_, s__] := Switch[Length[{s}],
  1, {Derivative[0, 1][func][t, s]},
  2, {Derivative[0, 1, 0][func][t, s], 
   Derivative[0, 0, 1][func][t, s]},
  3, {Derivative[0, 1, 0, 0][func][t, s], 
   Derivative[0, 0, 1, 0][func][t, s], 
   Derivative[0, 0, 0, 1][func][t, s]},
  4, {Derivative[0, 1, 0, 0, 0][func][t, s], 
   Derivative[0, 0, 1, 0, 0][func][t, s], 
   Derivative[0, 0, 0, 1, 0][func][t, s], 
   Derivative[0, 0, 0, 0, 1][func][t, s]},
  5, {Derivative[0, 1, 0, 0, 0, 0][func][t, s], 
   Derivative[0, 0, 1, 0, 0, 0][func][t, s], 
   Derivative[0, 0, 0, 1, 0, 0][func][t, s], 
   Derivative[0, 0, 0, 0, 1, 0][func][t, s], 
   Derivative[0, 0, 0, 0, 0, 1][func][t, s]}
  




  • Prev by Date: missing in Manipulate
  • Next by Date: Re: Better way to test the number of arguments?
  • Previous by thread: Re: missing in Manipulate
  • Next by thread: Re: Better way to test the number of arguments?