Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Function of N variable

78 views
Skip to first unread message

Sam Takoy

unread,
Aug 27, 2011, 8:19:45 AM8/27/11
to
Hi,

I have put together a few function for differential geometry in 3D.
All my functions were of the kind F(z1_, z2_, z3_). Now I want to
generalize to 4D, then 5D, etc. Is there a good way to represent a
function of N variables? For example, I want to be able to say grad[F]
[???] to obtain a list of N function (partial derivatives) of N
variables. I understand these are vague questions, but I am only
looking for some keywords.

Many thanks in advance,


Sam

Ethan Dyer

unread,
Aug 28, 2011, 4:05:44 AM8/28/11
to
Sam,

Mathematica allows one to define functions that take an arbitrary number of arguments using double underscore (BlankSequence) or triple underscore (BlankNullSequence)

For instance F[args__]:={args} takes in any number of arguments except zero.

A function defined with three underscores can take any number including zero.

Ethan

Sam Takoy

unread,
Aug 28, 2011, 4:09:50 AM8/28/11
to
E.G, the following?


Grad[f_][x__] := Switch[Length[{x}],
1, {Derivative[1][f][x]},
2, {Derivative[1, 0][f][x], Derivative[0, 1][f][x]},
3, {Derivative[1, 0, 0][f][x], Derivative[0, 1, 0][f][x],
Derivative[0, 0, 1][f][x]},
4, {Derivative[1, 0, 0, 0][f][x], Derivative[0, 1, 0, 0][f][x],
Derivative[0, 0, 1, 0][f][x], Derivative[0, 0, 0, 1][f][x]}]


f[x_, y_] = x^2 + y^2;
Grad[f][x, y]

Thanks!


________________________________
From: Ethan Dyer <ethan...@gmail.com>
To: Sam Takoy <sam....@yahoo.com>
Cc: "math...@smc.vnet.net" <math...@smc.vnet.net>
Sent: Saturday, August 27, 2011 9:24 AM
Subject: Re: Function of N variable

Ralph Dratman

unread,
Aug 28, 2011, 4:12:23 AM8/28/11
to
You could use something like F[{x1, x2,... xN}], that is, your argument to
the function would be a list of coordinates, rather than a fixed number.
Depending on other factors, you might or might not need an additional,
single-integer argument to specify the number of dimensions.

Ralph

0 new messages