English 中文(简体)
Introspection of messages generated in Mathematica
原标题:

Is there any way to get at the actual messages generated during the evaluation of an expression in Mathematica? Say I m numerically solving an ODE and it blows up, like so

In[1] := sol = NDSolve[{x [t] == -15 x[t], x[0] == 1}, x, {t, 0, 1}, 
                       Method -> "ExplicitEuler"];

In this case, I ll get the NDSolve::mxst error, telling me the maximum number of 10000 steps was reached at t == 0.08671962566152185. Now, if I look at the $MessageList variable, I only receive the message name; in particular, the information about the value of t where NDSolve decided to quit has been lost.

Now, I can always get that information from sol using the InterpolatingFunctionDomain function from one of the standard add-on packages, but if I can somehow pull it out of the message, it would be quite helpful.

最佳回答

You might be able to use $MessagePrePrint to set up a function which would store away each of the messages for later retrieval.

问题回答

I don t know if this will work, but if the only thing you want to know are the values of specific parameters at the point of error then a kludgy way of getting them would be to define those variables with dummy values globally. This works with loop counters, but I don t know if it works from within NDSolve. Another kludge would be to make t Dynamic and have an evaluated cell with t.

A more elegant (and probably the correct) approach would be to use Reap and Sow.





相关问题
Solving vector equations in Mathematica

I m trying to figure out how to use Mathematica to solve systems of equations where some of the variables and coefficients are vectors. A simple example would be something like where I know A, V, and ...

Introspection of messages generated in Mathematica

Is there any way to get at the actual messages generated during the evaluation of an expression in Mathematica? Say I m numerically solving an ODE and it blows up, like so In[1] := sol = NDSolve[{x [...

Connecting points in Mathematica

I have a collection of points displayed in a graphic: alt text http://img69.imageshack.us/img69/874/plc1k1lrqynuyshgrdegvfy.jpg I d like to know if there is any command that will connect them ...

Mathematica, PDF Curves and Shading

I need to plot a normal distribution and then shade some specific region of it. Right now I m doing this by creating a plot of the distribution and overlaying it with a RegionPlot. This is pretty ...

Targeted Simplify in Mathematica

I generate very long and complex analytic expressions of the general form: (...something not so complex...)(...ditto...)(...ditto...)...lots... When I try to use Simplify, Mathematica grinds to a ...

热门标签