I've been trying to solve a system of nonlinear differential equation, but the conditions are a bit weird.

Two of the differentials equate to the same equation, but have different boundary conditions. The third differential equate to something else.

For the background on the problem I am trying to solve, it is related to concentration as a function of time for a reaction.

Here is the code I have put, which was more or less straightforward, but I keep getting True. I've tried using DSolve and NDsolve, but I am unable to get a graph for my three concentration profiles (I do not need an analytical solution, just a graphical one).

A'[t] == -kf A[t] *B[t] + kb * c[t], 
B'[t] == -kf A[t] *B[t] + kb * c[t], 
c'[t] == kb * c[t] + kf A[t] B[t], 
A[0] == 1, B[0] == 2, c[0] == 0}, 
{A, B, c}, {t, 100}] 

kf and kb are constants I've already equated into my code.

But I keep resulting with:

NDSolve[{True, True, True, A[0] == 1, B[0] == 2, c[0] == 0}, {A, B, c}, {t, 100}]

I'm thinking it's because I'm multiplying two functions together, I haven't solved ODEs this way. I'd appreciate any input, or hints/guides/direction. Thanks!

If there is something unclear, or if I am lacking proper question asking etiquette please let me know!

  • 1
    $\begingroup$ Then you must have once mixed up = and ==. You need Clear[Derivative]. Values stored in Derivative can't be cleared by Clear["Global`*"] because it actually means clearing all the variables under context "Global`" while Context[Derivative] gives "System`". $\endgroup$ – xzczd Apr 16 '14 at 7:15
  • $\begingroup$ @xzczd New users might fall in to this Context trap. I haven't found another post to mark this as a duplicate. Perhaps your comment is worthy of an answer just so it is in the books? $\endgroup$ – bobthechemist Apr 16 '14 at 13:12
  • $\begingroup$ @bobthechemist OK, let me elaborate it into an answer. $\endgroup$ – xzczd Apr 16 '14 at 13:42
  • $\begingroup$ Apparently, I got to close this because it was originally tagged "plotting", since removed. I meant to just make it simple vote. If there's disagreement, respond or flag and maybe a moderator can help. $\endgroup$ – Michael E2 May 17 '15 at 15:08

Short Answer

Clear[Derivative] first.

Long Answer

OK, it's surprising that there seems to be no regular answer to this common problem for beginners, let me elaborate my comment into an answer. If you restart your Mathematica and run your code again then you'll find your problem no longer exists anymore! Then, why? Because Mathematica is unstable?

Of course not. Just recall what you've done before meeting the error, you may find the following scene in the corner of memory:

enter image description here

The value of kf and kb is chosen at random.

It's another common mistake of Mathematica newbies, that is, mix up = and ==.

Your code was in a mess now, but you didn't feel worried because you've already learned from some material that you can use


to fix this. You cheerfully placed this line at the beginning of your code and ran it again, only to find:

enter image description here

What happened? Why does the magic of Clear["Global`*"] lose its power?

To answer this I'd like to first explain why you need to clear the variables after you mistyped == to = since I presumingly guess you may still be vague about this. Try the following code:

A[0] = 0
A[0] == 0
A[0] == 0
A[0] == 0

BTW, though I've execute A[0] for several times to show the variation, you can judge whether A owns a value just by observing its color: it's black when it does, otherwise it'll be blue.

As you see, Set (=) will give value to its left hand side. (Of course there exist cases that the left hand side is Protected, for example a + b = 4 won't give the left side a value, but it's another story and I'd like not to talk about it here. ) If you don't Clear it, it'll be always there and break your equations. When introducing this issue, many materials will tell readers that you can simply use Clear["Global`*"] to "clear all the variables" at once, but it doesn't work for your case, yeah, you already know that, but do you know what's the exact meaning of Clear["Global`*"]?

If you check "Details" of document of Clear, you'll find the following description:

Clear["context`*"] clears all symbols in a particular context.

What's "context"? "context" is something that every symbol in Mathematica owns. You can check it by function Context, for example:


So Clear["Global`*"] is clearing the values of symbols under context Global`, which is the stronghold for most symbols that'll have values (at least for beginners), but, what you can Clear is only "most", not "all". Try the following code:

A'[0] = 0

Aha, A'[0] is one of the exceptions, the value of A'[0] isn't stored in A, in fact it's stored as SubValues (this is another story that I'd like to omit here, you can search it in this site or have a look at Leonid Shifrin's excellent book ) of Derivative, then what's the context of Derivative?:


So values in it can't be cleared by Clear["Global`*] (BTW 2, for most cases it can be shortened as Clear["`*"], meaning clear all the values of symbols under the current context, which is usually Global`), what you need to clear it is


Though some warnings generated, Clear["System`*"] can be used too if you like.

BTW 3, another symbol that is likely to trig this problem is Subscript.

  • $\begingroup$ @xzcxd: I must say this an excellent answer, one of the most helpful I have read. $\endgroup$ – David Nov 21 '14 at 17:33
  • 2
    $\begingroup$ I think it is a Mathematica design error to store derivative of a user symbol in the system context. Everything relating to user symbols/variables should be kept outside system context. Nothing should leak outside like with this example. $\endgroup$ – Nasser Nov 27 '14 at 5:29

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