So, How to write a python code which finds a rational number, which is closed to a fraction say f, without the use of standard function modules?
E.g., 3.14=22/7
Also the numerator and denominators have limits, like:
- numerator can't be greater than p
- denominator can't be greater than q.
My work:
# calculates i/j upto a precision of 0.001 closer to f.
while( abs((i/j)-f)> 0.001 and i<p, j<q):
j=j-1
i =?,
Now here I'm confused, How should I modify my i and j to make it work? Can I use Newton Raphson algorithm in any way??