40

Bug fixed in 10.0.0


I am having a rather unusual problem I do not understand with Mathematica where renaming one of the variables of my function causes the function to stop "working". Here is the example of the code doing what it should:

F[t_, a_, b_, l_] = x[t] /. First@
DSolve[{x'[t] == a*x[t]*(1 - (x[t]/b)) - l*x[t], x[0] == 0.4}, x[t], t];

Changing one variable name causes the code to throw out error messages. The non-working code is

F[t_, r_, b_, l_] = x[t] /. First@ DSolve[{x'[t] == r*x[t]*(1 -
(x[t]/b)) - l*x[t], x[0] == 0.4}, x[t], t];
xzczd
  • 65,995
  • 9
  • 163
  • 468
5xum
  • 503
  • 3
  • 8

2 Answers2

12

A little bit more. Still not fully diagnosed, but the problem isn't due to DSolve ... :

s1 = DSolve[{x'[t] == f*x[t] (1 - (x[t]/b)) - l x[t]}, x[t], t];
s2 = DSolve[{x'[t] == e*x[t] (1 - (x[t]/b)) - l x[t]}, x[t], t];

And the problem shows up when matching the initial condition:

Solve[(x[t] /. s2[[1]] /. t -> 0) == 4/10, C[1]]
(*
{{C[1] -> -(Log[1/2 (2 e - 5 b e + 5 b l)]/(b (e - l)))}}
*)

but

Solve[(x[t] /. s1[[1]] /. t -> 0) == 4/10, C[1]]

Solve::nsmet: This system cannot be solved with the methods available to Solve. >>

BTW,

Solve[(x[t] /. s1[[1]] /. t -> 0) == 4/10, C[1], Reals]

can be solved without any problem

Edit

I was able to track down the problem to:

Solve[E^(a w) (f - e) == E^(b w), {w}]

and

Solve[E^(a w) (f - g) == E^(b w), {w}]

only the first one gives a result!

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • 2
    Wow. I was sure I was missing something completely obvious, but the chaotic behavior makes me think this is just a very bizzare bug... – 5xum May 14 '13 at 14:00
  • @5xum Not obvious at all ... – Dr. belisarius May 14 '13 at 14:03
  • cant solve this regardless of etters..Solve[E^(a w) (f - 1 ) == E^w, {w}] – george2079 May 14 '13 at 20:28
  • 3
    @5xum An apparent bug indeed, and one that has persisted at least from version 7 through version 9. I'm surprised this hasn't been found and addressed in that time. – Mr.Wizard May 15 '13 at 04:36
  • A more simplified one: Solve[E^(a w) (b - 1) == E^w, w]. – Silvia May 16 '13 at 03:47
  • @Silvia Sorry, changing which letter does it turn solvable? – Dr. belisarius May 16 '13 at 03:50
  • I can't find a setting which makes it work.. But I believe it's the some issue. btw I traced to a System`Private`OldSolve function.. – Silvia May 16 '13 at 04:08
  • @Silvia Oh, I see now. Thanks! – Dr. belisarius May 16 '13 at 04:10
  • 3
    I guess this is a plain bug, a pattern matching messup that makes MMA think it can solve one expression and not the other. It's funny how it can solve the last example only if at least one of the two variables you add or subtract is sorted before the letter E (or whatever you put as base to that power) – Rojo May 16 '13 at 16:58
  • 2
    @Silvia Try the Solve[] with MaxExtraConditions -> All – Dr. belisarius May 17 '13 at 01:24
  • Wow didn't know this option! Thanks! – Silvia May 17 '13 at 02:47
  • @5xum If we can narrow down the bug to a specific set of variables, then it would be nice if the accepted answer patches(well monkey patches the issue) the issue maybe using Replace – William Jun 13 '13 at 00:19
7

The problem can be reduced to the DSolve expressions:

DSolve[{x'[t] == a*x[t]*(1 - (x[t]/b)) - l*x[t], x[0] == 0.4}, x[t], t]

DSolve[{x'[t] == h*x[t]*(1 - (x[t]/b)) - l*x[t], x[0] == 0.4}, x[t], t]

One can see that alphabetical order appears important:

With[{a = Symbol@#},
  Shallow @ DSolve[{x'[t] == a*x[t]*(1 - (x[t]/b)) - l*x[t], x[0] == 0.4}, x[t], t]
] & /@ DeleteCases[CharacterRange["a", "z"], "b" | "l" | "t" | "x"]
{{{Rule[<<2>>]}}, {{Rule[<<2>>]}}, {{Rule[<<2>>]}}, {{Rule[<<2>>]}}, {}, {}, {},
  {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}}

I suspect that this may be related to: Why does Simplify ignore an assumption?
Unfortunately I cannot think of a robust way to address the problem.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371