Re: SetPrecision vs N
- To: mathgroup at smc.vnet.net
- Subject: [mg71714] Re: SetPrecision vs N
- From: Peter Pein <petsie at dordos.net>
- Date: Mon, 27 Nov 2006 04:04:37 -0500 (EST)
- Organization: 1&1 Internet AG
- References: <ekbmmt$f9g$1@smc.vnet.net>
Andrew Moylan schrieb:
> Hi all,
>
> Suppose I want to evaluate an expression at a given precision. What is
> the difference between using N[expr, precision] and using
> SetPrecision[expr, precision]?
>
> I've noticed that SetPrecision seems to be equivalent even in such
> situations as e.g. N[Integrate[...]] automatically calling
> NIntegrate[...] when the integral can't be done exactly:
>
> SetPrecision[Integrate[x^x, {x, 0, 1}], 20]
> and
> N[Integrate[x^x, {x, 0, 1}], 20]
> both give
> 0.78343051071213440706
>
> Are there important differences between SetPrecision and N that I
> should be aware of?
>
> Cheers,
> Andrew
>
Hi Andrew,
the most obvious difference is:
Precision[N[1.1, 1000]]
--> MachinePrecision
vs.
Precision[SetPrecision[1.1, 1000]]
-->1000.
I guess, SetPrecision[#,prec]& automagically applies N[#,prec]& to an
expression having greater precision than prec (especially when applied to
exact expressions (which got infinite precision)).
P²