Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Better way to test the number of arguments?
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
pgeipi10@gmail.com

Posts: 3
Registered: 4/27/14
Better way to test the number of arguments?
Posted: Apr 27, 2014 2:42 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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]}






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.