Re: Coaxing N[] to work
- To: mathgroup at smc.vnet.net
- Subject: [mg73387] Re: Coaxing N[] to work
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Thu, 15 Feb 2007 04:57:51 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <equo6r$in0$1@smc.vnet.net>
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? > N[] cannot go from lower precision to higher. One way to deal with that is to use exact arithmetic as in the following example. In[1]:= x = {2, 3, 5}; A = {{6, 2, 1}, {2, 3, 1}, {1, 1, 1}}; Precision /@ x Precision /@ A For[k = 0, k < 15, ++k, lambda = x . A . x/x . x; y = LinearSolve[A, x]; x = y/Norm[y, Infinity]; ] lambda Precision[lambda] N[lambda, 30] Out[3]= {Infinity, Infinity, Infinity} Out[4]= {Infinity, Infinity, Infinity} Out[6]= 1102158619423970036337 ---------------------- 1903774504398915184457 Out[7]= Infinity Out[8]= 0.578933385691052787623495851172 Regards, Jean-Marc