numdig=. 100 NB. for the last pair of examples...
On Fri, Mar 5, 2010 at 12:58 PM, Devon McCormick <[email protected]> wrote:
> John - this converges much more quickly.
>
> While awaiting your reply, I used Cliff's suggestion (which seems to
> disagree with Leo's but I better understand it) which can be applied to work
> with the series you suggest:
>
> 10^.-/%/"1(1 3,:1 1)&(+/ .*)^:(20+i.2)]1 0x NB. Fewer than 11 digits
> _10.79625847621708
> 13j11":%/(10x^11)*(1 3,:1 1)&(+/ .*)^:20]1 0x NB. Last digit incorrect,
> as expected
> 1.73205080758
> 9!:11]16
>
> %:3
> 1.732050807568877
>
> NB. Generalizing this
> ]pcsn=. 10^.-/%/"1 sqrts3=. (1 3,:1 1)&(+/ .*)^:(100+i.2)]1 0x
> _56.55206227888699
> ]numdig=. <.-pcsn NB. Safe enough to round precision down?
> 56
> ((2+numdig)j. numdig)":%/1{sqrts3 NB. "1{" to be extra sure...
> 1.73205080756887729352744634150587236694280525381038062806
> #'1.732050807568877293527446341' NB. From
> http://www.research.att.com/~njas/sequences/A040001<http://www.research.att.com/%7Enjas/sequences/A040001>
> 29
>
> So, it looks like "format" is smart enough to preserve precision according
> to its left argument when given a rational fraction as its right argument?
> That's helpful.
>
> Using the method John sent:
>
> ]pcsn=. 10^.-/%/"1 sqrts3=. f^:(7 8) 1 1x
> _72.66969546124619
> ]numdig=. <.-pcsn
> 72
> ((2+numdig)j. numdig)":%/1{sqrts3
> 1.732050807568877293527446341505872366942805253810380628055806979451933017
> NB. "1{" is gilding the lily:
> ((2+numdig)j. numdig)":%/0{sqrts3
> 1.732050807568877293527446341505872366942805253810380628055806979451933017
>
> ((2+numdig)j. numdig)":%/0{sqrts3
>
> 1.7320508075688772935274463415058723669428052538103806280558069794519330171227462181522446767406659571
> ((2+numdig)j. numdig)":%/1{sqrts3
>
> 1.7320508075688772935274463415058723669428052538103806280558069794519330169088000370811461867572485757
>
>
>
> On Fri, Mar 5, 2010 at 12:28 PM, John Randall <
> [email protected]> wrote:
>
>> Devon McCormick wrote:
>> > Members of the Forum -
>> >
>> > If I'm approximating, e.g. the square root of 3, with a matrix method
>> > which
>> > returns an extended precision numerator and denominator, when I work out
>> > the
>> > decimal equivalent of this, at what point do I run out of significant
>> > digits?
>> >
>>
>> Devon:
>>
>> You can do much better with these Pell-type estimates, since you can
>> generate estimates 2,4,8,16,... directly: If your last estimate was p/q,
>> your next estimate is ((*:p)+3**:q)%2*p*q.
>>
>>
>> f=:((1 3)&(+/ .*)@:*:),+:@(*/)
>>
>> f^:(i.5) 1 1x
>> 1 1
>> 4 2
>> 28 16
>> 1552 896
>> 4817152 2781184
>>
>> (%:3)-%/f^:3 ] 1 1x
>> _9.20496e_5
>> (%:3)-%/f^:4 ] 1 1x
>> _2.44585e_9
>> (%:3)-%/f^:5 ] 1 1x
>> 0
>>
>> Best wishes,
>>
>> John
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
>
>
> --
> Devon McCormick, CFA
> ^me^ at acm.
> org is my
> preferred e-mail
>
>
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm