0

we know that Pell equation is expressed as

enter image description here

which in case of D is not perfect square, can be approximated by continued fraction expansion of D, for instance let us consider such kind of equation

enter image description here

square root of 61 can be approximated by following matlab code

>> b=sqrt(61);
>> format rat
>> b

b =

    1523/195  

but i have question : how can i assign result in two separate variable ?namely

x=1523 
y=195

from this site https://www.quora.com/What-is-the-fast-way-to-solve-the-fundamental-solution-of-Pell-equation

i understood that solution are based on numerator and denumerator, how can i assign fraction parts to x and y during the code in matlab? thanks in advance

1 Answers1

2

While, by definition, an irrational number can never be exactly represented as a ratio of integers, it can approximately represented via such a ratio in finite precision arithmetic. This can be done through the rat function to varying degrees of approximation:

>> [n,d] = rat(sqrt(61),1E-4);  (n/d) - sqrt(61)
ans =
   9.5152e-05
>> [n,d] = rat(sqrt(61),1E-8);  (n/d) - sqrt(61)
ans =
  -4.4218e-09
>> [n,d] = rat(sqrt(61),1E-16);  (n/d) - sqrt(61)
ans =
     0

It is noted that the final 0 does not indicate true equality of the terms; just equality to the limits of double precision arithmetic.

TroyHaskin
  • 8,361
  • 3
  • 22
  • 22
  • so easy thanks very much , i got point, now what about if we have like this 2+3*sqrt(2) ? how can i access 2 and 3? –  Apr 03 '17 at 07:03