d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > Math Question
Add Reply New Topic New Poll
Member
Posts: 167
Joined: Oct 2 2014
Gold: 0.00
Jan 18 2015 02:01pm
Use a Casio calculator to find a fraction p/q, p< 10^6 that approximates sqrt(2) with a truncation error less than 10^(-10). For this use

sqrt(a) = lim n-> infinity {x_n}
where

x_0 = a/2, x_(n+1) = 1/2(x_n + a/(x_n))
Member
Posts: 16,662
Joined: Nov 24 2007
Gold: 15,245.00
Trader: Trusted
Jan 18 2015 02:36pm
Using rational numbers to approximate any real number : continued fractions are the best way.
For sqrt(2) as any algebraic number of degree 2, it's quite easy :

sqrt(2) = [ 1 ; 2 ; 2 ; 2 ; ... ]

which means that sqrt(2) can be approximate with :
1/1
3/2
7/5
17/12
41/29
99/70
239/169
...
275807/195025

You are asked to use a specific algorithm, involving a specific sequence ?

Variables :
P : integer
Q : integer

Initialisation :
P = Q = 1

Treatment :

While | P/Q - sqrt(2) | > 10^(-10), repeat :
P² + 2Q² -> P
2PQ -> Q
End

Output :
display P
display Q

This post was edited by feanur on Jan 18 2015 02:36pm
Go Back To Homework Help Topic List
Add Reply New Topic New Poll