3
$\begingroup$

I can't find a Clear or ClearAll command that gets rid of Derivative definitions I created. this code:

ClearAll["Global`*"];
gau[x_, v_] = (1/Sqrt[2*Pi*v])*E^-((x^2)/(2*v));
Derivative[0, n_][p][x, v] := Simplify[D[gau[z, v], {v, n}]];
ClearAll["Global`*"];
gau[x_, v_] = (1/Sqrt[2*Pi*v])*E^-((x^2)/(2*v));
Derivative[0, n_][p][x, v] := Simplify[D[gau[z, v], {v, n}]/gau[z, v]];
D[p[x, v], {v, 2}]

produces output consistent with the 1st definition, not the second.

$\endgroup$
1

1 Answer 1

3
$\begingroup$

First of all you most likely want to define your functions with patterns x_, y_ instead of fixed symbols x, y. Second, you can use Unset to achieve what (I think) you want. This is needed because Derivative is not in the Global context, but instead in the System context. So your ClearAll command doesn't affect it. But you also don't want to just say ClearAll[Derivative] because that may remove definitions you still need. Unset is more specific. You use it as follows:

Derivative[0,n_][p][x_,v_]=.

This can still be combined with the ClearAll["Global*"]; that you already had, to make sure other definitions are removed.

$\endgroup$
3
  • $\begingroup$ Will ClearAll[Derivative] only clear the derivs that I defined? Or will it mess up MMa built-in functions? $\endgroup$ Mar 5, 2015 at 7:09
  • 1
    $\begingroup$ Since Derivative is not protected, ClearAll[Derivative] would indeed affect its properties. E.g., I checked SubValues[Derivative] before and after, and there is a difference... $\endgroup$
    – Jens
    Mar 5, 2015 at 14:41
  • $\begingroup$ Is the reason you recommend patterns here incase he tries to find a function with different variable names (than x,v)? $\endgroup$
    – user106860
    Oct 20, 2020 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.