comp.lang.ada
 help / color / mirror / Atom feed
From: antispam@math.uni.wroc.pl
Subject: Re: Fun with Unbounded Rational Numbers
Date: Sun, 9 Apr 2017 19:25:05 +0000 (UTC)
Date: 2017-04-09T19:25:05+00:00	[thread overview]
Message-ID: <oce1qh$let$1@z-news.wcss.wroc.pl> (raw)
In-Reply-To: occs8h$6f4$1@dont-email.me

Jeffrey R. Carter <spam.jrcarter.not@spam.not.acm.org> wrote:
> On 04/09/2017 02:30 AM, antispam@math.uni.wroc.pl wrote:
> >
> > newton(y : Fraction(Integer), eps : Fraction(Integer)) : Fraction(Integer) ==
> >     x : Fraction(Integer) := 1
> >     while abs(y - x^2) >= eps repeat
> >         x := (x + y/x)/2
> >     x
> 
> Maybe I'm missing something, but this doesn't look like Newton's method to me.
> 

We are sloving equation f(x) - y = 0 where f(x) = x^2.  Newton says:

x_{n+1} = x_{n} - (f(x_n) - y)/f'(x_n)

we have

f'(x) = 2x

so

x_{n+1} = x_{n} - (x_n^2 - y)/(2*(x_n)) =
          x_{n} - x_n^2/(2*(x_n)) + y/(2*(x_n)) =
          x_{n} - x_n/2 + y/(2*(x_n)) =
          x_{n}/2 + y/(2*(x_n)) = (x_{n} + y/x_n)/2
       
So indeed given the same initial approximation the formula produces
exactly the same sequence of numbers as direct use of Newton formula,
but is slightly cheaper to compute.

-- 
                              Waldek Hebisch

  reply	other threads:[~2017-04-09 19:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-08 10:37 Fun with Unbounded Rational Numbers Jeffrey R. Carter
2017-04-08 11:19 ` Dmitry A. Kazakov
2017-04-08 14:14 ` Robert Eachus
2017-04-09  0:30 ` antispam
2017-04-09  8:47   ` Jeffrey R. Carter
2017-04-09 19:25     ` antispam [this message]
2017-04-10 17:18       ` Jeffrey R. Carter
2017-04-11 21:39         ` antispam
2017-04-09  7:15 ` Paul Rubin
2017-04-09  8:56   ` Jeffrey R. Carter
2017-04-09 21:18     ` Paul Rubin
2017-04-10 17:08       ` Jeffrey R. Carter
2017-04-10 19:39         ` Paul Rubin
2017-04-09 10:05   ` Jeffrey R. Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox