Re: Overloading functions
- To: mathgroup at smc.vnet.net
- Subject: [mg119106] Re: Overloading functions
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Sun, 22 May 2011 06:53:19 -0400 (EDT)
You You defined only ONE f -- not two -- with two different argument patterns. Your operator works only for the first argument pattern, because MyOperator[f][x,y,z] doesn't match your LHS pattern for MyOperator. You could change it to this: Clear[myOperator, f] myOperator[g_][x_, y_] := 4 + Derivative[1, 0][g][x, y]; myOperator[g_][x_, y_, z_] := 4 + Derivative[1, 0, 0][g][x, y, z]; f[x_, y_] = x + y; f[x_, y_, z_] = 2 x + 2 y + 2 z; myOperator[f][x, y] myOperator[f][x, y, z] 5 6 Bobby On Sat, 21 May 2011 05:50:38 -0500, Sam Takoy <sam.takoy at yahoo.com> wrote: > Hi, > > In the following code > > MyOperator[g_][x_, y_] = 4 + Derivative[1, 0][g][x, y]; > > f[x_, y_] = x + y; > f[x_, y_, z_] = 2 x + 2 y + 2 z; > > MyOperator[f][x, y] > > > how does Mathematica know which f to send to MyOperator. Can someone > outline the formal decision tree that Mathematica follows? > > Thanks! > > Sam > -- DrMajorBob at yahoo.com