One solution is to Quit
the kernel. On the toolbar, use Evaluation->Quit Kernel->Local
. That will clear all of your variables, but it's almost the only sure thing you can do, besides quitting Mathematica. Nothing like a fresh start.
Two other solutions are Unset[y'[x]]
and Remove[y]
, which are more subtle. These solutions are good if you know what the problem is.
So what happened? Surprisingly, Mathematica lets us make assignments to y'[x]
, similar to how we make assignments to symbols. It's an easy typographical error to make when entering differential equations. For instance, when we want to solve a 2nd order DE and inadvertently enter y'[0]=1
instead of y'[0]==1
. We can make a typo in the DE or in ICs or in both. If you will bear with me, I will show you a few error messages and how to fix them.
Create a problem
Starting with a fresh kernel, suppose we evaluate this statement containing a typographical error:
DSolve[{y''[x] == 1, y[0] == 0, y'[0] = 1}, y, x]
We get the error message
DSolve::deqn: Equation or list of equations expected instead of 1 in the first argument {(y^′′)[x]==1,y[0]==0,1}.
If we read the error message closely we see that the last of our equations was misinterpreted as a 1. When we check our input we see that our last equation contains an assignment (=) instead of an equals (==). So we fix it and hit Shift-Enter, and get almost the same error message. What? So we try to ClearAll["Global
*"]`, check our equation and hit Shift-Enter again. It still doesn't work!
Fix the problem
Now type in Quit[]
followed by Shift-Enter. Try to execute the DSolve
command and now it works.
Okay, now re-create the problem and try to fix it with Unset[y'[0]]
. That works, too. Also try re-creating the problem and fixing it with Remove[y]
.
Re-create the original problem
To recreate the same problem as in your original question you can execute the assignment y'[x] = -y[x]
. Now when you evaluate your DSolve
command, you get the error message. You can fix the problem by executing either Quit[]
or Unset[y'[x]]
or Remove[y]
at the keyboard, or by using Quit Kernel on the toolbar. Again, this is a common typographical error and you will get used to seeing the error message. You will soon instinctively check the equals signs before even reading the error message.
I personally use Quit
from the toolbar because (1) it sometimes tells me a second kernel is running and (2) I don't like having Quit[]
in my notebooks.