Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Coaxing N[] to work

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73386] Re: [mg73370] Coaxing N[] to work
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Thu, 15 Feb 2007 04:57:18 -0500 (EST)
  • References: <200702141020.FAA19038@smc.vnet.net>

On Feb 14, 2007, at 5:20 AM, <p at dirac.org> wrote:

> Sometimes N[,] doesn't appear to work.  Like here:
>
>
> x = {2.0, 3.0, 5.0};
> A = { {6.0, 2.0, 1.0}, {2.0, 3.0, 1.0}, {1.0, 1.0, 1.0} };
> For[ k=0, k<15, ++k,
>    lambda = x.A.x/(x.x);
>    y = LinearSolve[A,x];
>    x = y / Norm[y,Infinity];
> ]
> N[lambda, 30]
>
>
> The output is:
>
>    Out[5]= 0.578933
>
> I was expecting 30 digits.  Why did N[] ignore my request for 30  
> digits

Mathematica can't create precision out of nowhere, you only specified  
2 digits of precision for the elements of x and A, fortunately  
Mathematica actually used machine precision numbers and gave you 16,  
but it can't read your mind and give you 30.  Since lambda has 16  
digits of precision it's treated as a machine precision number and  
prints out as such.  Here's how to put 30 digits of precision on x  
and A:

In[1]:=
x =SetPrecision[{2.0, 3.0, 5.0},30];
A = SetPrecision[{ {6.0, 2.0, 1.0}, {2.0, 3.0, 1.0}, {1.0, 1.0,  
1.0} },30];
For[ k=0, k<15, ++k,
    lambda = x.A.x/(x.x);
    y = LinearSolve[A,x];
    x = y / Norm[y,Infinity];
]
N[lambda, 30]

Out[4]=
0.5789333856910527876234959

Regards,

Ssezi




  • Prev by Date: Re: Comments in the front end
  • Next by Date: Re: Coaxing N[] to work
  • Previous by thread: Coaxing N[] to work
  • Next by thread: Re: Coaxing N[] to work