15
$\begingroup$

I entered a command incorrectly as follows:

    DSolve[{y'[x]=y[x]},y[x],x]

I am now experiencing:

    DSolve[{y'[x] == y[x]}, y[x], x]

During evaluation of In[26]:= DSolve::deqn: Equation or list of equations expected instead of True in the first argument {True}. >>

(* DSolve[{True},y(x),x] *)

How do I recover from this error. I've tried Clear[y'[x]]. That didn't work.

$\endgroup$
  • 2
    $\begingroup$ Remove[y] will do the trick. $\endgroup$ – ciao Jan 13 '14 at 6:25
  • $\begingroup$ That worked! Thanks. $\endgroup$ – David Jan 13 '14 at 6:43
  • $\begingroup$ Related: (373) $\endgroup$ – Mr.Wizard Jan 13 '14 at 8:09
  • $\begingroup$ @rasher I caution against using Remove here! It will break any definitions that reference y, and it will alter even localized appearances of the Symbol, though the definitions may still work. Try e.g. fn[y_] := Sin[y]; Remove[y]; Definition[fn] $\endgroup$ – Mr.Wizard Jan 13 '14 at 8:34
  • $\begingroup$ @Mr.Wizard: Good point. Probably gave too quick-n-dirty, emphasis on dirty, solution. $\endgroup$ – ciao Jan 13 '14 at 8:38
17
$\begingroup$

It is for situations like this that Unset exists. :-)

After the mistaken Set operation:

y'[x] = "oh dear";

y'[x]
"oh dear"

Merely use:

y'[x] =. 

The definition is cleared:

y'[x]
y'[x]

Please see halirutan's answer for an explanation of why ClearAll[y] does not work here.

$\endgroup$
12
$\begingroup$

Very tricky mistake because hard to track down. The problem is that y'[x] parses as

Derivative[1][y][x]

Therefore, your assignment is not to the symbol y but to the symbol Derivative and since you have multiple call like f[][] it goes into its SubValues:

SubValues[Derivative]
(* {HoldPattern[Derivative[1][y][x]] :> y[x]} *)

Therefore, evaluate

SubValues[Derivative] = {};

and the sun shines again

DSolve[{y'[x] == y[x]}, y[x], x]
(* {{y[x] -> E^x C[1]}} *)
$\endgroup$
  • 1
    $\begingroup$ If there are any other SubValues defined for Deritative this non-specific clearing will not be appropriate. In version 7 for example there are definitions for InverseLaplaceTransform by default. $\endgroup$ – Mr.Wizard Jan 13 '14 at 8:37
  • $\begingroup$ @Mr.Wizard Yes, you are of course right. My answer was rather an explanation what happens than the correct way to solve the problem. I upvoted your answer, since Unset is the way to go IMO $\endgroup$ – halirutan Jan 13 '14 at 17:07
  • $\begingroup$ I added a note to my answer directing readers to yours, because they are complementary. $\endgroup$ – Mr.Wizard Jan 13 '14 at 17:16
  • $\begingroup$ I just noticed that technically this answer was incorrect. Evaluation of y'[x] is not the issue as one can see with HoldPattern[y'[x]] = "bad"; rather y'[x] parses as Derivative[1][y][x], as seen with HoldForm @ FullForm[y'[x]]. I am editing this answer accordingly. $\endgroup$ – Mr.Wizard May 1 '16 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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