Message Boards Message Boards

0
|
9337 Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Mathematica 10: Plot[] No Longer Plots Equations (?)

Posted 10 years ago

Try this

ClearAll[eqn, ics, ode]
eqn = x''[t] + 20.*x'[t] + 30.*x[t] == 35.*Sin[2.*Pi*2.*t]
ics = {x[0] == 0., x'[0] == 0.}
ode = Flatten[{eqn, ics}]

ClearAll[sol];
sol = NDSolve[ode, x, {t, 0, 5.}, AccuracyGoal -> 14, PrecisionGoal -> 14][[1]]

Plot[Evaluate[eqn /. sol], {t, 0, 5.}]

The Plot command yields empty plot in Mathematica 10, but in 9.0.1 and 8.0.4 a plot results.

I often have many differential equations I would like to plot to see the effects of Accuracy and Precision goals and the above is a simple, rough way to do it.

Even this no longer works in Mathematica 10, but does in 9.0.1 and 8.0.4:

Plot[Evaluate[2 x^2 + 3 x == 20], {x, -5, 5}]

It seems a bit burdensome to do

Plot[Evaluate[eqn[[1]] - eqn[[2]] /. sol], {t, 0, 5.}, PlotRange -> All]

especially if I have quite a few differential equations.

Suggestions welcome unless this is unintended behavior, then Wolfram guys please let me know.

Notebook attached.

-B

Attachments:
POSTED BY: Brian Lamm
5 Replies
Posted 10 years ago

I also find it strange that this ever worked. Maybe it was undocumented behavior similar to ContourPlot's acceptance of an equation as an argument. However, pattern substitution could be used to provide similar functionality.

In[3]:= eq = 2 x^2 + 3 x == 20

Out[3]= 3 x + 2 x^2 == 20

In[4]:= eq /. a_ == b_ -> a - b

Out[4]= -20 + 3 x + 2 x^2
POSTED BY: David Keith
Posted 10 years ago

Thanks much Eric. I believe WRI's position will be this is intended behavior since as you point out the documentation has, for a long time now, read that the first argument is treated as a function. I too wonder why it used to work and now it does not. It appears not to be a subtle task to move all terms of an equation expression to one side of == and then get rid of the == resulting in an expression which can be treated as a function.

POSTED BY: Brian Lamm
Posted 10 years ago

@Eric, I believe you may have misunderstood what I try to do. I am not trying to plot the solution. I try to plot the equation. Are you amazed that

Plot[Evaluate[2 x^2 + 3 x == 20], {x, -5, 5}]

ever worked? The above yields empty plot in Mathematica 10, but not in 8.0.4 and 9.0.1.

When I try to plot the differential equation with the solution replacement, what I am trying to do is see how well the equation was satisfied with the solution found.

You should then be equally amazed that

Plot[Evaluate[eqn[[1]] - eqn[[2]] /. sol], {t, 0, 5.}, PlotRange -> All]

enter image description here

does work in Mathematica 10, and is equivalent to plotting the equation with solution replacement, although somewhat more burdensome when many equations are present.

POSTED BY: Brian Lamm
Posted 10 years ago

You're right I did not understand what you were asking. However, I'm still perplexed since Plot plots functions, not equations.

2 x^2 + 3 x == 20

This is not a function. What's surprising to me is Mathematica used to turn it into a function for you automagically in the past. The fact it used to work is interesting and I'm not sure why.

Plot[Evaluate[eqn[[1]] - eqn[[2]] /. sol], {t, 0, 5.}, PlotRange -> All]

eqn[[1]]-eqn[[2]] is indeed a function (there is no == in it) and plots just fine as expected.

I realize none of this is an answer as to why Mathematica handles it differently now.

POSTED BY: Eric Meyers
Posted 10 years ago

I'm amazed that ever worked. The proper way is

Plot[Evaluate[x[t] /. sol], {t, 0, 5.}]

enter image description here

POSTED BY: Eric Meyers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract