2
$\begingroup$

I just started to use Mathematica and to help me solve a differential equation, I copied the following differential equation from wolfram page just for practice:

s= NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}]

But I get the following error message, similar to the one I get when I tried to solve my differential equation: NDSolve::derivs: No derivatives of dependent variables were found in the equations. NDSolve is designed to solve differential or differential algebraic equations. Use NSolve or FindRoot to numerically solve algebraic equations.

Does anyone know what could possibly be wrong? If I add another ' to the y'[x] to make it second order and add another boundary condition it works.

$\endgroup$
  • 1
    $\begingroup$ It works fine on V11.0.1 $\endgroup$ – zhk Sep 26 '17 at 1:38
  • $\begingroup$ It outputs NDSolve[{-y[x] == Cos[x + y[x]] y[x], y[0] == 1}, y, {x, 0, 30}]. I am not sure as to why my first order derivatives change to a -y[x]. Is this something I can change? I have version 11.2 Student edition. $\endgroup$ – Daniel Sep 26 '17 at 1:39
  • $\begingroup$ Works fine in V11.2 on Linux. What OS do you have? $\endgroup$ – user21 Sep 26 '17 at 1:46
  • $\begingroup$ I have Linux-x86-64 ubuntu. $\endgroup$ – Daniel Sep 26 '17 at 1:47
  • 1
    $\begingroup$ Runs fine on V11.2 on Windows 10. I suggest that you restart Mathematica and run your single line of code in a new notebook. $\endgroup$ – bbgodfrey Sep 26 '17 at 3:41
2
$\begingroup$

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.

$\endgroup$

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.