Re: When ploting a differential equation, sigularities cause big ugly vertical lines on the graph - how can I get rid of them? By some magic mathematica incantaion?

*To*: mathgroup at smc.vnet.net*Subject*: [mg25182] Re: When ploting a differential equation, sigularities cause big ugly vertical lines on the graph - how can I get rid of them? By some magic mathematica incantaion?*From*: "Allan Hayes" <hay at haystack.demon.co.uk>*Date*: Tue, 12 Sep 2000 21:24:25 -0400 (EDT)*References*: <8pklfd$m91@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Ed, Using Split we can write a function that operates on Graphics objects and splits lines at points where the absolute slope gets big, In[7]:= DeleteVerticals[gr_Graphics, slopeMax_] := gr /. Line[lst_] :> Map[Line, Split[lst, Abs[Divide @@ Reverse[#1 - #2]] < slopeMax &], 1]; I apply this to your problem: sol = Table[ NDSolve[{y'[t] == y[t] - y[t]^2/12 - 4, y[0] == i}, y, {t, 0, 8}], {i, 4, 20, 4}] gr = Plot[Evaluate[y[t] /. sol], {t, 0, 8}, AspectRatio -> 1, PlotRange -> {0, 20}, FrameLabel -> {"Fish Population - Fixed Harvesting", y'[t] == y[t] - y[t]^2/12 - 4}, Frame -> True, ImageSize -> 300] Show[DeleteVerticals[gr, 1000]] We can also use the perceived slope In[6]:= DeleteVerticals2[gr_Graphics, slopeMax_] := gr /. Line[lst_] :> Module[{xmin, xmax, ymin, ymax, ar, scl}, (*get the plot range and the aspect ratio used*) {{{xmin, xmax}, {ymin, ymax}}, ar} = Last /@ AbsoluteOptions[gr, {PlotRange, AspectRatio}]; (* multiplying by scl converts a slope in user coordinates to the \ slope as seen - see note below*) scl = ar (xmax - xmin)/(ymax - ymin); Map[Line, Split[lst, Abs[Divide @@ Reverse[#1 - #2]] scl < slopeMax &], 1]]; -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "Ed" <ejh at idcomm.com> wrote in message news:8pklfd$m91 at smc.vnet.net... > Howdy All! > > When ploting a differential equation, sigularities cause big ugly > vertical lines on the graph. > > For example if I am graphing a family of solutions curves, each of > which decreases exponentially, at least some of them will be treated > as signularities by mathematica, and the place where they become too > funky for mathematica, there is an ugly vertical line. > > I would like to plot a function only within a certain range, and when > it leaves that range I would like mathematica to stop computing the > function. > > Alternatively I could use any possible advice on how to turn off these > vertical lines. Here's an example function with these singularities: > > In[2]:= > Table[NDSolve[{y'[t] == y[t]-y[t]^2/12-4, y[0] == i}, y, {t, > 0,8}],{i,4,20,4}] > > NDSolve::"ndsz": > "At \!\(t\) == \!\(3.62756604743090482`\), step size is > effectively zero; \ > singularity suspected." > NDSolve::"ndsz": > "At \!\(t\) == \!\(7.25517865610478196`\), step size is > effectively zero; \ > singularity suspected." > Out[2]= > {{{y\[Rule]InterpolatingFunction[{{0.,3.62757}},"<>"]}},{{ > y\[Rule]InterpolatingFunction[{{0.,7.25518}},"<>"]}},{{ > y\[Rule]InterpolatingFunction[{{0.,8.}},"<>"]}},{{ > y\[Rule]InterpolatingFunction[{{0.,8.}},"<>"]}},{{ > y\[Rule]InterpolatingFunction[{{0.,8.}},"<>"]}}} > > > Here's the plotting command I am using: > > In[3]:= > Plot[Evaluate[ y[t] /. %2], {t, 0, > 8},AspectRatio->1,PlotRange->{0,20}, > FrameLabel->{"Fish Population - Fixed Harvesting", > y'[t] == y[t]-y[t]^2/12-4}, Frame->True,ImageSize->300] > InterpolatingFunction::"dmval": > "Input value \!\({3.65410229958301835`}\) lies outside the range > of data \ > in the interpolating function. Extrapolation will be used." > InterpolatingFunction::"dmval": > "Input value \!\({3.63388315790337124`}\) lies outside the range > of data \ > in the interpolating function. Extrapolation will be used." > InterpolatingFunction::"dmval": > "Input value \!\({3.62853932022043901`}\) lies outside the range > of data \ > in the interpolating function. Extrapolation will be used." > General::"stop": > "Further output of \!\(InterpolatingFunction :: \"dmval\"\) will > be \ > suppressed during this calculation." > > > >