Can someone help me understand the evaluation procedure in the following two pieces of code?
test[] := Module[{expression},
Clear[F];
expression = Derivative[0,1][F][x,y];
F[x_,y_] = y-x^2+1;
Return[expression];
];
test[func_] := Module[{expression},
Clear[F];
expression = Derivative[0,1][F][x,y];
F[x_,y_] = func;
Return[expression];
];
test[]
test[y - x^2 + 1]
1
0
I expected the output to be 1 in the second case.
I believe the major issue (which we can identify using Trace) is that when test is called without an argument, F is assigned as expected:
F[x_,y_]=y-x^2+1;
However, when test is called with an argument, F receives a different assignment using locally defined variables:
F[x$_,y$_]=y-x^2+1;
If I can figure out how to have F assigned as in the former, then I believe my issue will be resolved and the outputs will match.
Context: I know there is an easier way to compute a partial derivative with respect to a variable, however that is not my ultimate goal. In the end, expression will be much more complex and involve mixed partial derivatives of F. I want Mathematica to replace all the instances of these Derivatives. I do not think I can use a ReplaceAll since I am not sure what Derivatives will actually show up.
(F^(0,1))[x,y], do you meanD[F[x,y],y]? And second, what happens if you put the definition (F[x_,y_]) before the evaluation ofexpression? I think that will work ! – Sumit Apr 23 '15 at 18:04expression := D[F[x, y], y]for the second one? – Sumit Apr 23 '15 at 18:27expressionwill involveDerivativeand notD. – James Rohal Apr 23 '15 at 18:29F[u_, v_] = func /. {x -> u, y -> v}– 2012rcampion Apr 23 '15 at 18:41