0
$\begingroup$
a = -5; 
c = 5; 
Clear[solution, x, y, fakey]; 
solution = NDSolve[{y'[x] == (y[x]^2) - 1, y[0] == 0.9}, y, {x, a, c}]

This gives me the following error:

NDSolve::deqn: Equation or list of equations expected instead of True 
in the first argument {True, y[0] == 0.9}.

Which is strange because I copy/pasted NDSolve from the documentation and swapped in values.

$\endgroup$
2
  • $\begingroup$ Just a stupid question (hoping that I may) : why NDSolve and not DSolve or even just integration by hand ? $\endgroup$ Commented Jan 15, 2018 at 7:15
  • $\begingroup$ First find its analytic solution for an idea about function behaviour. ..Somewhat like ... $ y = \tanh (x/2+ c)$ ; Next find a good mid-interval value for $y$ and trouble point in the domain ; the following works. a = -5; c = 5; Clear[solution, x, y, fakey]; solution = NDSolve[{y'[x] == (y[x]^2) - 1, y[0] == -3}, y, {x, a, c}] yy[u_] = y[u] /. First[%] Plot[ yy[x], {x, .1, 3}, GridLines -> Automatic, PlotRange -> All] $\endgroup$
    – Narasimham
    Commented Jan 15, 2018 at 17:27

1 Answer 1

4
$\begingroup$

First of all, this question is more appropriate for Mathematica.SE rather that here.

At first I posted the following comment, which I now have deleted:

You must've copied it wrong. I've just copy-and-pasted the four lines from your question into Mathematica on my computer, and it gave me an output: {{y -> InterpolatingFunction[{{-5., 5.}}, <>]}}.

But then I figured that there's something else going on. I started a new notebook, so there was no possible interference from any previous inputs in my case. But what if something that happened earlier in your notebook affected the output in your case? And then I was able to reproduce this effect! It's not about NDSolve at all…

I bet when you entered it first, you made a very common typo by using = instead of == in the equation to be solved:

a = -5;
c = 5;
Clear[solution, x, y, fakey];
solution = NDSolve[{y'[x] = (y[x]^2) - 1, y[0] == 0.9}, y, {x, a, c}]`

to which Mathematica responded

NDSolve::deqn: Equation or list of equations expected instead of -1+y[x]^2 in the first argument {-1+y[x]^2,y[0]==0.9}.

Then you realized your error and corrected your input:

a = -5;
c = 5;
Clear[solution, x, y, fakey];
solution = NDSolve[{y'[x] == (y[x]^2) - 1, y[0] == 0.9}, y, {x, a, c}]

and saw this puzzling response

NDSolve::deqn: Equation or list of equations expected instead of True in the first argument {True,y[0]==0.9}.

The reason this happened: in your first input, the clause y'[x] = (y[x]^2) - 1 was an assignment, resulting in y'[x] now actually storing the expression (y[x]^2) - 1. Next time, when you compare them with each other, the comparison naturally returned True since they are equal to each other! Note that Clear[y] had no effect on y'[x] because roughly speaking it's a different symbol for Mathematica.

$\endgroup$
1
  • 1
    $\begingroup$ Conclusion : when you see thigs like that, restart typing ClearAll["Global`*"]. Cheers and $+1$ for the good analysis. $\endgroup$ Commented Jan 15, 2018 at 7:08