MathGroup Archive 2007

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

Search the Archive

Re: Coaxing N[] to work

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73384] Re: [mg73370] Coaxing N[] to work
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 15 Feb 2007 04:56:12 -0500 (EST)
  • Reply-to: hanlonr at cox.net

For machine precision input, the output will be a machine precision number.

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];]
lambda

0.578933

%//InputForm

0.5789333856910527

Providing higher precision input numbers will give a more precise output. However, some precision is lost in the calculation.

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

0.5789333856910527876234959

For very high precision use exact numbers (Rationalize)

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

1102158619423970036337/1903774504398915184457

N[lambda,30]

0.578933385691052787623495851172


Bob Hanlon

---- 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?
> 



  • Prev by Date: Re: Coaxing N[] to work
  • Next by Date: Re: Coaxing N[] to work
  • Previous by thread: Re: Coaxing N[] to work
  • Next by thread: Re: Coaxing N[] to work