g = 9.81;
k = 0.009;
r = 10;
b = 0;
ω = Sqrt[g/r];
NDSolve[{r/g*y''[x] + (k*r/g + b*r^2/mg)*y'[x]^2 + Cos[x] - k*Sin[x] == 0,
y[0] == π/2, y'[0] == ω}, y, {x, 0, 2}]
Regarding to this question, NDSolve
evaluates the ODE without an error message. NDSolve
doesn't evaluate the term b*r^2/mg
because b == 0
, although the variable mg
is unknown. This is not correct in my opinion.
Is it a bug?
Answer
I think the issue behind this question is actually interesting. Not-so-experienced Mathematica users often suffer an illusion: the internal functions will merge when they are used together.
In your case, you probably felt that NDSolve
together with the equations and initial conditions have merged to something that will solve the ODE. "So, what happened inside this something?" "Hmm, I don't know, and I believe no body knows, it happened internally." Unfortunately, as said above, it's generally not true. When functions are used together, they will just execute from inner to outer. (This order will be adjusted by attributes like HoldAll
, HoldFirst
, etc. of course.)
A choice to show the process is to use Trace
, you can also try the functions in this post. Here I'll use WReach's traceView2
:
NDSolve[{r/g y''[x] + (k r/g + b r^2/mg) y'[x]^2 + Cos[x] - k Sin[x] == 0,
y[0] == π/2, y'[0] == ω}, y, {x, 0, 2}] // traceView2
Pictured by Simon Wood's shadow.
As you see, the equation inside NDSolve
is executed before NDSolve
begins to work.
Finally, though not quite related, I'd like to mention that, the merge effect does exist in some very rare case, for example this.
Comments
Post a Comment