RE: RE: "f[x_]:= 2 x" vs. "f = 2 #&"
- To: mathgroup at smc.vnet.net
- Subject: [mg16531] RE: [mg16467] RE: [mg16365] "f[x_]:= 2 x" vs. "f = 2 #&"
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Tue, 16 Mar 1999 04:00:08 -0500
- Sender: owner-wri-mathgroup at wolfram.com
I will update the discussion and demonstrations in my MathSource item to
take into account the remarks from Andrzej Kozlowski, Jurgen Tisher, and
Allan Hayes.
(1) Contrary to what I thought, it is legal to use patterns on the right
side of a definition.
(2) Early in my notebook I give an example where I claim Plot would make an
erratic graph. My Pentium makes an erratic graph when I use Plot for this
example. Using a Mac Plot makes a smooth graph for the same example.
Thanks,
Ted
---------------------------
Ted,
how about the following?
PrecisionPlot[f_,{x_,xmin_,xmax_}]:=Module[{g,h},
g[y_]:=(f/.x->y);
h[y_]:=g[SetPrecision[y,100]];
Plot[h[x],{x,xmin,xmax}]]
Jurgen
"Ersek, Ted R" wrote:
>
................
> -------------------------------
> Suppose you are writing a program with the form
> func[x_]:= (*****algorithm*****)
> and (algorithm) has to make a function that will be used at later stages
of
> (algorithm).
>
> It's illegal to use patterns on the right side of a definition.
> So (algorithm) can't make the function with the approach
> f[x_]:= 2 x
> It also can't make the function with the approach
> f[x_]= 2 x
> Instead (algorithm) must make the function with one of the following
> f=2#&
> f=Function[2#]
> f=Function[x,2x]
>
> So when would you need to do this?
> One such case is the function below. This function will plot a function
> using arbitrary precision arithmetic to sample the function. This is
useful
> in special cases when a function must be sampled using arbitrary precision
> arithmetic.
>
> (***********)
> PrecisionPlot[f_,{x_,xmin_,xmax_},opts___?OptionQ]:=
> Module[{g,h},
> (g=Function[f/.x->#];
> h=(g[SetPrecision[#,17]]&);
> Plot[h[x],{x,xmin,xmax},opts]
> )
> ]
> (***********)
>
> As far as I can tell there was no way to get PrecisionPlot working without
> using a pure function as I do with g=Function[f/.x->#]
>
..................