MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Accuracy and Precision

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36897] Re: Accuracy and Precision
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Tue, 1 Oct 2002 04:45:31 -0400 (EDT)
  • References: <an8s8i$6pk$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Andrzej, Bobby, Peter

It looks as if using SetAccuracy succeeds here because the inexact numbers
that occur have finite binary representations. If we change them slightly to
avoid this then we have to use Rationalize:

1) Using SetAccuracy

    Clear[a,b,f]

    f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/(2*b),
      Infinity];

    a=77617.1;
    b=33096.1;

    a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity];

    f

        -1564032114908486835197494923989618867972540153873951942813115514949
3891236234\

5250077191686937045911977601879880463043614978691991293196257430102923631246
75\

/108671061439707605510003578275547938881981431359756495796079898677435728240
16\
        0653953612982932181371232436367739737604096

2) Rewriting as fractions

    a=776171/10;
    b=330961/10;

    f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b)

        -(5954133808997234115690303589909929091649391296257/
           41370125000000)

3) Using Rationalize

    Clear[a,b,f]


f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/(2*b),0];

    a=77617.1;
    b=33096.1;

    a=Rationalize[a,0];b=Rationalize[b,0];

    f

        -(5954133808997234115690303589909929091649391296257/
           41370125000000)


I use Rationalize[. , 0] besause of results like

    Rationalize[3.1415959]

        3.1416

    Rationalize[3.1415959,0]

        31415959/10000000
--
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


"Andrzej Kozlowski" <andrzej at tuins.ac.jp> wrote in message
news:an8s8i$6pk$1 at smc.vnet.net...
> Well, first of of all, your using SetAccuracy and SetPrecision does
> nothing at all here, since they do not change the value of a or b. You
> should use a = SetAccuracy[a, Infinity] etc. But even then you won't
> get the same answer as  when you use exact numbers because of the way
> you evaluate f. Here is the order of evaluation that will give you the
> same answer, and should explain what is going on:
>
> f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*
>          b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity];
>
> a = 77617.;
>
>
>   b = 33096.;
>
> a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity];
>
> f
>
>    54767
> -(-----)
>    66192
>
> Andrzej Kozlowski
> Toyama International University
> JAPAN
>
>
>
> On Sunday, September 29, 2002, at 03:55 PM, Peter Kosta wrote:
>
> > Could someone explain what is going on here, please?
> >
> > In[1]:=
> > a = 77617.; b = 33096.;
> >
> > In[2]:=
> > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity];
> > SetPrecision[a, Infinity]; SetPrecision[b, Infinity];
> >
> > In[4]:=
> > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 +
> > a/(2*b)
> >
> > In[5]:=
> > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity];
> >
> > In[6]:=
> > f
> >
> > Out[6]=
> > -1.1805916207174113*^21
> >
> > In[7]:=
> > a = 77617; b = 33096;
> >
> > In[8]:=
> > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) +
> > (55/10)*b^8 + a/(2*b)
> >
> > In[9]:=
> > g
> >
> > Out[9]=
> > -(54767/66192)
> >
> > In[10]:=
> > N[%]
> >
> > Out[10]=
> > -0.8273960599468214
> >
> > Thanks,
> >
> > PK
> >
> >
> >
>
>




  • Prev by Date: Animations -- delete after viewing
  • Next by Date: RE: Accuracy and Precision
  • Previous by thread: Re: Accuracy and Precision
  • Next by thread: RE: Accuracy and Precision