Re: Plot function at specific points

*To*: mathgroup at smc.vnet.net*Subject*: [mg114114] Re: Plot function at specific points*From*: "István Zachar" <replicatorzed at gmail.com>*Date*: Wed, 24 Nov 2010 06:58:05 -0500 (EST)

This is indeed a cheater solution : ) And a twofolded cheater, though rather clever: first, it is messy in the sense that the eps threshold is something arbitrary, and second, it still goes over the 10000 iterations - something that I definitely want to avoid if I have a set of explicit query-points. I'm sure that somehow the plotting algorithm can be instructed via the Method option to sample at specific locations, though I still haven't found any info about such possibilities. In the meantime I've crafted the following workaround, following the v6 extension of Table to list iterators: f == Interpolation[{{0, 1}, {1, 2}, {2, 3}, {3, 5}, {4, 8}, {5, 5}, {6, 2}, {7, 1}, {8, 1}, {9, 2}, {10, 4}}]; g == Interpolation[{{0, 3}, {1, 4}, {2, 5}, {3, 5}, {4, 5}, {5, 4}, {6, 3}, {7, 2}, {8, 1}, {9, 1}, {10, 0}}]; lowRes == Range[0, 10, 2]; Unprotect[Plot]; Plot[func_, {x_, range_}, opts___] /; MatchQ[range, {__?NumericQ}] :== ListPlot[ Transpose@Outer[{#1, #2[#1]} &, range, If[ListQ@func, func, {func}]], opts, Joined -> True]; Protect[Plot]; Plot[{f, g}, {x, lowRes}] Plot[g, {x, lowRes}] I see no objection why this extension shouldn't be part of v9 in the future (or even of v8.0.1) : ) Of course some proper option-handling must be added as well, and it must be extended to LogPlot and relatives, but I think I'll use this until someone can reveal the scope of Method inside Plot. Thanks again for the suggestions, Istvan On 2010.11.23. 14:51, Leonid Shifrin wrote: > Hi Istvan, > > You are likely to get much better solutions, but here is one way > (cheating somewhat): > > f == Interpolation[{{0, 1}, {1, 2}, {2, 3}, {3, 5}, {4, 8}, {5, 5}, {6, > 2}, {7, 1}, {8, 1}, {9, 2}, {10, 4}}]; > lowRes == Range[0, 10, 2]; > eps == 0.001; > cutF == Function[ > Evaluate[ > Module[{x}, > Total[UnitStep[x - # + eps]*UnitStep[# + eps - x] & /@ > lowRes] /. x -> #]]]; > Plot[f[x]*cutF[x], {x, 0, 10}, PlotRange -> {{0, 10}, {0, 9}}, > PlotPoints -> 10000, PlotStyle -> {Thickness[0.005]}] > > If your f[x] is expensive to compute, you can define f[x]cutF[x] as a > single function and > compute f[x] lazily only when cutF[x] is non-zero. > > Regards, > Leonid > > > 2010/11/23 Istv=E1n Zachar <zac at freemail.hu <mailto:zac at freemail.hu>> > > Dear Group, > > is there a method to plot an InterpolatingFunction at specific pointr > WITHIN Plot? I am of course aware that I can use ListPlot at any time= , > though for certain reasons I have to stick with Plot. The main reason > is that I have a large amount of InterpolatingFunctions which I plot > with Plot as default, though at request I have to plot the same > InterpolatingFunctions at different resolutions. PlotPoints and > MaxRecursion is no good here, since lower resolution has to use a > certain set of x-values, defined prior to plotting. Obviously I want > to use the same Plot setup for both high and low-resolution cases. > Below is a toy modell of the problem: > > f == Interpolation[{{0, 1}, {1, 2}, {2, 3}, {3, 5}, {4, 8}, {5, 5}, {= 6, > 2}, {7, 1}, {8, 1}, {9, 2}, {10, 4}}]; > lowRes == Range[0, 10, 2]; > Plot[f[x], {x, 0, 10}, PlotRange -> {{0, 10}, {0, 9}}] > ListLinePlot[{#, f@#} & /@ lowRes, PlotRange -> {{0, 10}, {0, 9}}] > > Again, what I want is to have a specific Plot call instead of the > ListLinePlot, but with same result as ListLinePlot. > Note that values of 'lowRes' may not correspond the exact x- > coordinates supplied to f. > > Is there a way to tell Plot explicitly the steps to use? Any idea? > > Istvan > >