The procedure is the same for Q4 and Q5, so there's no need to treat them separately. If you know how to do one, you know how to do them all.

The 4 is chosen because $\displaystyle 4^2 < 23$ and $\displaystyle 5^2 > 23$.

Printable View

- Jun 8th 2010, 09:11 AMundefined
- Jun 8th 2010, 09:17 AMAmer
$\displaystyle \sqrt{5} $

the floor of sqrt[5] is 2

$\displaystyle \sqrt{5} = 2 + \sqrt{5} -2 = 2 + \frac{(\sqrt{5}-2)(\sqrt{5}+2)}{\sqrt{5}+2}= 2 + \frac{5 -4}{\sqrt{5}+2} = 2 + \frac{1}{\sqrt{5}+2} $

[2 ;

$\displaystyle \sqrt{5}+2 = 4 + \sqrt{5} - 2 $

[2;4

$\displaystyle \sqrt{5} - 2 = \frac{(\sqrt{5}-2)(\sqrt{5}+2)}{\sqrt{5}+2} = \frac{1}{\sqrt{5} +2 } $

$\displaystyle \sqrt{5} +2 = 4 + \sqrt{5} - 2 $

[2;4,4

and so on - Jun 8th 2010, 09:23 AMSamson
- Jun 8th 2010, 09:26 AMSamson
- Jun 8th 2010, 09:31 AMundefined
- Jun 8th 2010, 09:32 AMAmer
$\displaystyle \sqrt{7} $ the has the floor 2

$\displaystyle \sqrt{7} = 2 + \frac{\sqrt{7} -2}{1} = 2 + \frac{3}{\sqrt{7}+2} $

turned over $\displaystyle \frac{3}{\sqrt{7}+2}$

$\displaystyle \frac{\sqrt{7}+2}{3} $ we say before $\displaystyle \sqrt{7} = 2 +\sqrt{7}-2 $

so

$\displaystyle \frac{2+\sqrt{7} -2 +2 }{3} = \frac{4 + \sqrt{7}-2}{3} = 1 + \frac{\sqrt{7} -1}{3}= 1 + \frac{7-1}{3(\sqrt{7}+1)}= \frac{6}{3(\sqrt{7}+1)} $

turned over $\displaystyle \frac{6}{3(\sqrt{7}+1)} $

$\displaystyle \frac{\sqrt{7}+1}{2} $ multiply with the conjugate and so on

i find [2;1

can u continue ? - Jun 8th 2010, 09:50 AMSamson
Okay, first off, what's the point of turning it over to get

$\displaystyle \frac{45}{\sqrt{7}+2}$ and $\displaystyle \frac{6}{3(\sqrt{7}+1)} $ (respectively) ?

Then, how did you get from

$\displaystyle \frac{4 + \sqrt{7}-2}{3} $ to $\displaystyle 1 + \frac{\sqrt{7} -1}{3} $ ?

Lastly, when did you know to place 2 and 1 in the list like you did ( [2;1 ) ? - Jun 8th 2010, 10:07 AMAmer
in fact I'm just doing what in here

the way is for example we want to find continued fraction of sqrt[s]

let f=floor of sqrt[s] ok

then it is trivial that

sqrt[s] = f + sqrt[s] - f, is it ok for now if it then we find the first number

[f;

now we say sqrt[s] = f + (sqrt[s] - f ) the expression in the brackets multiply it with it is conjugate

$\displaystyle \frac{(\sqrt{s}-f)(\sqrt{s}+f)}{\sqrt{s}+f} = \frac{s - f^2}{\sqrt{s}+f} $

turn over it

$\displaystyle \frac{\sqrt{s}+f}{s - f^2} $ we say that sqrt[s] = f + sqrt[s] - f

so

$\displaystyle \frac{\sqrt{s}+f}{s - f^2} = \frac{2f + \sqrt{s} - f }{s - f^2 } $

suppose that 2f/(s-f^2) = r + t/(s-f^2) , r is integer so

$\displaystyle \frac{2f + \sqrt{s} - f }{s - f^2 } = r + \frac{ \sqrt{s} - f +t}{s-f^2} $

[f;r,

$\displaystyle \frac{ \sqrt{s} - f +t}{s-f^2} $ multiply with the conjugate then turn over and so on - Jun 8th 2010, 10:11 AMSamson
I'm trying to follow you, but I think if you worked with the explicit example I had pointed out I'd understand. Those are the steps I'm missing.

- Jun 8th 2010, 10:20 AMAmer
I worked it in sqrt[7] and sqrt[5]

read them

hope u will get the answer - Jun 8th 2010, 10:24 AMSamson
- Jun 8th 2010, 10:33 AMundefined
- Jun 8th 2010, 10:45 AMSamson
Thank you for that explanation, that is exactly what I needed. I will try to apply this, but if anyone wants to add anymore onto either Sqrt[5] or Sqrt[7], please feel free. I'll be logging on later and it would be great if I had something to check my work against!

- Jul 2nd 2010, 03:44 AMSamson
- Jul 3rd 2010, 11:51 PMundefined
Here's my code:

Code:`import java.util.ArrayList;`

public class ContFracSqrt {

static boolean v=true; // verbosity

public static void main(String[] args) {

print(cfe(5));

}

static void print(ArrayList<Integer> a) {

int i;

String s=a.toString();

if(a.size()>1)

for(i=2;;i++)

if(s.charAt(i)==',') {

s=s.substring(0,i)+"; ("+s.substring(i+2);

s=s.substring(0,s.length()-1)+")]";

break;

}

System.out.println(s);

}

static ArrayList<Integer> cfe(int n) {

ArrayList<Integer> x=new ArrayList<Integer>();

int a=(int)Math.sqrt(n),b=a,c=1,d,e,f,g;

x.add(a);

if(a*a==n) return x;

if(v) System.out.println("\\sqrt{"+n+"}="+a+"+\\dfrac{\\sqrt{"+n+"}-"+a+"}{1}");

if(v) System.out.print("\\dfrac{1}{\\sqrt{"+n+"}-"+a+"}=");

while(true) {

d=c;

c=n-b*b;

g=gcd(c,d);

c/=g;

d/=g;

b=-b;

f=a-c;

for(e=0;b<=f;e++)

b+=c;

x.add(e);

if(v) System.out.println(e+"+\\dfrac{\\sqrt{"+n+"}-"+b+"}{"+c+"}");

if(b==a&&c==1) return x;

if(v) System.out.print("\\dfrac{"+c+"}{\\sqrt{"+n+"}-"+b+"}=");

}

}

static int gcd(int a,int b) {

return (b==0)?a:gcd(b,a%b);

}

}

$\displaystyle \sqrt{5}=2+\dfrac{\sqrt{5}-2}{1}$

$\displaystyle \dfrac{1}{\sqrt{5}-2}=4+\dfrac{\sqrt{5}-2}{1}$

$\displaystyle [2; (4)]$

and for $\displaystyle \displaystyle \sqrt{7}$:

$\displaystyle \sqrt{7}=2+\dfrac{\sqrt{7}-2}{1}$

$\displaystyle \dfrac{1}{\sqrt{7}-2}=1+\dfrac{\sqrt{7}-1}{3}$

$\displaystyle \dfrac{3}{\sqrt{7}-1}=1+\dfrac{\sqrt{7}-1}{2}$

$\displaystyle \dfrac{2}{\sqrt{7}-1}=1+\dfrac{\sqrt{7}-2}{3}$

$\displaystyle \dfrac{3}{\sqrt{7}-2}=4+\dfrac{\sqrt{7}-2}{1}$

$\displaystyle [2; (1, 1, 1, 4)]$

Let me know how this works for you. I decided against ASCII mode since LaTeX is so much nicer.