Re: DifferenceOrder command

*To*: mathgroup at smc.vnet.net*Subject*: [mg55671] Re: DifferenceOrder command*From*: mtrott at wolfram.com*Date*: Sat, 2 Apr 2005 01:28:01 -0500 (EST)*References*: <d2j9r3$t5$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Jesse Sheinwald wrote: > A couple of the PDE example problems that use NDSolve in The Mathematic > Guidebook for Programming use the parameter DifferenceOrder. I cannot find > it in the Mathematica help files (v5.1.1.0) or in the Mathematica book > (v.5). What does it mean and how can I get it? Needless to say programs > using that parameter fail to run. The Mathematica GuideBooks for Programming and Graphics went into page formatting and printing before Mathematica 5 was released. As a result, the printed books show inputs and outputs relevant to Mathematica Version 4. (For most of the Mathematica functions discussed in the Programming volume, this is of no relevance.) Because making the DVD was/is faster than printing a book, I had time to update the inputs to version 5 on the DVD notebooks. But because version 5 was still relatively new at this time (spring last year), and some users might still have used version 4 at this time, I made all changes to version 5 through the initialization file. This allowed to make sure that the inputs run in version 4 and in version 5. So, if you run say the input nsol = NDSolve[{pde == 0, \[Psi][x, 0] == \[Psi]0[x], \[Psi][xM, t] == \[Psi][-xM, t]}, \[Psi][x, t], {x, -xM, xM}, {t, 0, T}, (* set options for a solution appropriate for visualization *) AccuracyGoal -> 2, PrecisionGoal -> 2, StartingStepSize -> {2xM/1100, Automatic}, MaxSteps -> 20000, DifferenceOrder -> 10]; from Chapter 1 of the Programming volume in version 4, it will just work fine. If you run it in version 5, it will also run fine and produce a correct result, but will in addition give the message: TMGBsV4ToV5::ndsdo: DifferenceOrder was an option of NDSolve in Mathematica \ Version 4. It is no longer an option of NDSolve in Mathematica Version 5. The \ initialization file of the Mathematica GuideBooks redefined the function \ NDSolve to automatically use DifferenceOrder as a suboption of the Method \ option instead. This message is generated through the initialization file of the GuideBooks directory. After generating this message, the NDSolve call is rewritten to the V5 syntax and the new NDSolve expression s evaluated. (Have a look at the initialization file to see how this works in detail.) The explicit frm of the correspodning version 5 input would be: nsol = NDSolve[{pde == 0, \[Psi][x, 0] == \[Psi]0[x], \[Psi][xM, t] == \[Psi][-xM, t]}, \[Psi][x, t], {x, -xM, xM}, {t, 0, T}, (* set options for a solution appropriate for visualization *) AccuracyGoal -> 2, PrecisionGoal -> 2, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "DifferenceOrder" -> 10, "MaxPoints" -> {1200}, "MinPoints" -> {1200}}}]; In version 4, NDSolve had the option DifferenceOrder: In[1]:= $Version Out[1]= "4.0 for Linux (January 5, 2000)" In[2]:= Options[NDSolve] Out[2]= {AccuracyGoal -> Automatic, Compiled -> True, DifferenceOrder -> Automatic, InterpolationPrecision -> Automatic, MaxRelativeStepSize -> 1, MaxSteps -> Automatic, MaxStepSize -> Infinity, Method -> Automatic, PrecisionGoal -> Automatic, SolveDelayed -> False, StartingStepSize -> Automatic, StoppingTest -> None, WorkingPrecision -> 16} In version 5, DifferenceOrder is no longer a top-level option: In[1]:= $Version Out[1]= "5.0 for Linux (November 18, 2003)" In[2]:= Options[NDSolve] Out[2]= {AccuracyGoal -> Automatic, Compiled -> True, DependentVariables -> Automatic, EvaluationMonitor -> None, MaxStepFraction -> 1/10, MaxSteps -> Automatic, MaxStepSize -> Automatic, Method -> Automatic, NormFunction -> Automatic, PrecisionGoal -> Automatic, SolveDelayed -> False, StartingStepSize -> Automatic, StepMonitor -> None, StoppingTest -> None, WorkingPrecision -> MachinePrecision} But if you have a look in the advanced documentation for NDSolve in Version 5, you find that "DifferenceOrder" is now a suboption of the "SpatialDiscretization" option of the "MethodOfLines" method of the Method option of NDSolve. The top-level options of the function MethodOfLines from the NDSolve` context are: In[3]:= Options[NDSolve`MethodOfLines] Out[3]= {"DifferentiateBoundaryConditions" -> True, "DiscretizedMonitorVariables" -> False, "ExpandEquationsSymbolically" -> False, "Method" -> Automatic, "SpatialDiscretization" -> "TensorProductGrid", "TemporalVariable" -> Automatic} The forthcoming (revised and expanded compared with the versions on the Programming DVD) Numerics and Symbolics volumes of the Mathematica GuideBook are tailored for Mathematica 5.1, so that the above messages will no longer be issued. These two volumes should be available in a few weeks; in the moment the pages are being formatted and will then go to print. The printed books will have 5.1 code and the DVDs will also have 5.1 code. Michael Trott