aldweb

Fermer I. aldweb

Fermer II. Gratuitiels PC

Fermer III. Gratuitiels Palm

Fermer IV. Partagiciels Palm

Fermer V. iziBasic Palm

Fermer VI. Connaissance Palm

Fermer VII. Ordinateur Poche

Fermer VIII. miniPortail

Spécial !



Version mobile
de l'aldweb Site

m.aldweb.com


Ni Français, ni Anglais ?

Essayez donc l'un de ces drapeaux :
[de] [es] [it] [pt]
Recherche




Météo / Spam / www

Météo Lyon


aldweb contre le SPAM


Newsletter
Pour avoir des nouvelles de ce site, inscrivez-vous à notre Newsletter.
S'abonner
Se désabonner
298 Abonnés
Sites web de la famille

Webmaster - Infos
News Amis
Visites

   visiteurs

   visiteurs en ligne

Sondage
Comment trouve-tu le nouvel habillage de l'aldweb Site ?
 
Superbe !
Joli
Moyen
Moche...
Résultats
forum.gifForum - Pocket Computer - Sujet n°19

Forum - Forum
Pocket Computer - Pocket Computer


Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 257

actif  Sujet n° 19  convert decimal to fraction

le 09/12/2002 @ 20:45
par ERNESTO

Anonyme



HI
I LOOKING FOR FOR A PROGRAM IN BASIC
TO CONVERT DECIMAL TO FRACTION.
EXEMPLE :
RATIO =.301886
FRACTION = 16/53
I HAVE SEVERAL POCKET COMPUTER
LIKE SHARP 1500 ALSO SHARP EL-9600c
AND CASIO FX-880P.
I HOPE YOU CAN GIMME A HAND
ALSO I NEED THE MORE LOWER FACTOR BECAUSE
THIS APPLICATION IS FOR FIGURING SET OF
GEARS FOR MACHINES TO CUT GEARS
THANK YOU
ERNESTO HERNANDEZ








;
Ecrire à ERNESTO   Poster une réponse  Haut

[]   


Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 1
--------
le 09/12/2002 @ 21:56
par aldweb

Anonyme

visiteur
Hello Ernesto and welcome on this forum :-)

Your request for a program being able to find a fraction from a real number is a wonderful thing. I wish I would be able to find the algorithm to do it, but it by far outpasses my programming knowledge.

Anybody else has got an idea?
We could think about running a friendly competition among us on this topic. What do you think of it?
Ecrire à aldweb   Poster une réponse  Haut

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 2
--------
le 16/12/2002 @ 15:37
par Madis K.

Anonyme

visiteur
Lets open our eyes and try some simpe things.
I think you have already tried that, but I would go and multiply X with Y & INC(Y) every cycle, till X*Y becomes a integer value. Then I would make the fraction simpler by dividing a number of times both A and Y in formula A/Y.
Another thing is to start increasing Value of Y in formula 1/Y.
IF 1/Y<X THEN X=X+1 ELSEIF 1/Y>X then do one of the following:
1)Take the integer part away from the X or
2)Subsitute 1 with variable and increase it
IF 1/Y=X THEN just print the value on the screen or keep it in secret:)
About the first one:You take the INT away!!!
this means you have to add it later and you get a value like a_b/c
In the second you get a value like a/b <=a is sometimes bigger than b.
Hope it helps;D
You know what to do when it won't
Ecrire à Madis K.   Poster une réponse  Haut

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 3
--------
le 16/12/2002 @ 21:48
par Sébastien

Anonyme

visiteur
Sorry for multiple replies, I had some problem with the answer window...

I give here the basic idea of a method that yields series of fractions approximating more and more accurately a given floating point number.
First, start with a positive number r0. The trivial approximating fraction of r0 at rank zero is... surprise: u0/1 where u0 = [r0] is the integer part of r0!
Then subtract [r0] from r0, giving a positive number r1 in range [0, 1). r1 is the inverse of this new number. Now take the integer part of r1: u1 = [r1]. A new approximating fraction of r0 is now:
1
u0 + ---
u1

The idea is to recursively apply the method over the ri terms, yielding:
1
u0 + ---------------
1
u1 + ---------

u2 + etc.

Now the problem is to compute *incrementally* the fraction. I give a method (without demonstration!):
Let N(-1) = 1
and D(-1) = 0
and N(0) = [r0]
and D(0) = 1
and U(0) = r0 - N(0)
and R(0) = r0
then at rank i we have:
N(i) = N(i-1) * U(i) + N(i-2)
D(i) = D(i-1) * U(i) + D(i-2)
where U(i) = [1 / R(i-1)]
and R(i) = 1 / R(i-1) - U(i)

Programmed in Objective Caml and applied to acos(-1) (~pi) it yields:

22./7. (Archimede's approximation)
333./106.
355./113. (A well-known pi approximation)
103993./33102.
104348./33215.
etc.

Writing the BASIC program that computes the series of approximating fractions is let as an exercice to the reader!
Note: The halt condition may be something like:

abs (r0 - N(i) / D(i)) / r0 < epsilon

(relative convergence)

I hope I've not made too many mistakes...

Cheers,

Sébastien
Ecrire à Sébastien   Poster une réponse  Haut

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 4
--------
le 17/12/2002 @ 10:03
par Sébastien

Anonyme

visiteur
After one night full of mathematical dreams, I would suggest to work only on the mantissa of r0 (by multiplying it by its base 10-logarithm). It should avoid bad results when r0 is too small. After running the algorithm, just add trailing zeroes to the numerator in case of positive logarithm or to the denominator otherwise.

Cheers,

Sébastien.
Ecrire à Sébastien   Poster une réponse  Haut

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 5
--------
le 17/12/2002 @ 10:22
par Sébastien

Anonyme

visiteur
Aldweb,

Just a little suggestion about this forum: Is it possible to *keep* spaces at the beginning of a line to avoid bad formatting like this:

1
u0 + ---------------
1
u1 + ---------

u2 + etc.

when I wrote that:

...........1
u0 + ---------------
...............1
......u1 + ---------

............u2 + etc.

Thank you!

Sébastien.
Ecrire à Sébastien   Poster une réponse  Haut

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 6
--------
le 17/12/2002 @ 22:14
par aldweb

Anonyme

visiteur
Sébastien,

It's done :-)
  It's done :-)
    It's done :-)
      It's done ;:-)
    It's done :-)
  It's done :-)
It's done :-)
Ecrire à aldweb   Poster une réponse  Haut

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 7
--------
le 17/12/2002 @ 23:02
par aldweb

Anonyme

visiteur
Oups, I forgot to say that you have to leave at least 2 SPACES at the beginning of a line for this to be effective.
Ecrire à aldweb   Poster une réponse  Haut

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 8
--------
le 18/12/2002 @ 19:18
par Sébastien

Anonyme

visiteur
  Thank you!
    P-S: Just a little test,
      to see...

         Sébastien.
Ecrire à Sébastien   Poster une réponse  Haut
actif sujet actif   clos sujet clos   Important! Important!   Nouveau Nouveau message   -   Rectifier Rectifier message   Clôturer Clôturer sujet   Remonter Remonter
[]
Catégories de discussion  Forum 



 
^ Haut ^