S = 3 1 0
Define P = b a , where a , b are natural numbers less than 1 0 0 0
Find a + b such that P has a value closest to S , or mathematically ∣ P − S ∣ is minimised
a , b are co-prime natural numbers.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Very nice, if I may say so.
i also did the same great
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
It returns (4.310285048436668e-06, 851, 395)
Here is a beginner's way to solve this problem: brute force. The code below is self explanatory:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
I did the same way , I love brute force searches.
@Raghav Vaidyanathan is this code for netbeans????
Log in to reply
no. C++, i used borland compiler.
Log in to reply
do u know how to operate on netbeans???
Log in to reply
@Aditya Kumar – Sorry, I do not.
Log in to reply
@Raghav Vaidyanathan – thats fine :)
Log in to reply
@Aditya Kumar – NetBeans is a compiler isn't it?
Log in to reply
@Arulx Z – NetBeans is an IDE.
def f(x,d,k):
for a in range(1,k):
for b in range(1,k):
P = a/b
e = abs(P-x)
if e < d:
print(e,a,b)
x is the value we wish to find a close fraction for. d is our delta value, i.e. our acceptable margin of error. k is how large our domain of natural numbers should be.
I used Python or this code. Essentially I wrote a double for loop to let Python go through every value of a/b, but ignore those that had a margin of error larger than my delta requirement. I then looked at the printed values and chose the a and b that resulted in the smallest epsilon, or error, value. The "a" and "b" that led to this were 851 and 395.
1 2 3 4 5 6 7 8 |
|
One need not search the entire space of (a,b)'s. Indeed, the following code could be tightened. The variable 'k' is present because I was checking the code for smaller values of it.
sir, can u suggest a code for netbeans??
Log in to reply
NetBeans is a development platform--see the wikipedia article. So I assume you mean code for Java. I'm afraid I haven't written anything in that language for twenty years or so.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
1 2 3 4 5 6 |
|
Problem Loading...
Note Loading...
Set Loading...
With enough patience, we can get the continued fraction of 3 1 0 to be [ 2 ; 6 , 2 , 9 , 1 , 1 , 2 , 4 , … ]
So we want to input as much nested fractions, trial and error shows that for constraint for numerator and denominator to be less than 1 0 0 0 would give the fraction below (with natural number x )
2 + 6 + 2 + 9 + 1 + 1 + x 1 1 1 1 1 = 1 3 6 x + 2 5 9 2 9 3 x + 5 5 8
Substitute x = 1 gives a = 8 5 1 , b = 3 9 5